未验证 提交 08f11d51 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

[TD-5007]<fix>: use build directory's taosdump to test. (#6711)

btw, solve two taosdemo test cases too.
上级 f2611d08
...@@ -17,6 +17,7 @@ import argparse ...@@ -17,6 +17,7 @@ import argparse
import os.path import os.path
import json import json
class taosdemoPerformace: class taosdemoPerformace:
def __init__(self, commitID, dbName): def __init__(self, commitID, dbName):
self.commitID = commitID self.commitID = commitID
...@@ -30,7 +31,7 @@ class taosdemoPerformace: ...@@ -30,7 +31,7 @@ class taosdemoPerformace:
self.user, self.user,
self.password, self.password,
self.config) self.config)
self.insertDB = "insertDB"; self.insertDB = "insertDB"
def generateJson(self): def generateJson(self):
db = { db = {
...@@ -41,7 +42,7 @@ class taosdemoPerformace: ...@@ -41,7 +42,7 @@ class taosdemoPerformace:
stb = { stb = {
"name": "meters", "name": "meters",
"child_table_exists":"no", "child_table_exists": "no",
"childtable_count": 10000, "childtable_count": 10000,
"childtable_prefix": "stb_", "childtable_prefix": "stb_",
"auto_create_table": "no", "auto_create_table": "no",
...@@ -62,7 +63,7 @@ class taosdemoPerformace: ...@@ -62,7 +63,7 @@ class taosdemoPerformace:
{"type": "INT", "count": 4} {"type": "INT", "count": 4}
], ],
"tags": [ "tags": [
{"type": "INT", "count":1}, {"type": "INT", "count": 1},
{"type": "BINARY", "len": 16} {"type": "BINARY", "len": 16}
] ]
} }
...@@ -103,17 +104,49 @@ class taosdemoPerformace: ...@@ -103,17 +104,49 @@ class taosdemoPerformace:
cmd.close() cmd.close()
return output return output
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosdemo" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def insertData(self): def insertData(self):
os.system("taosdemo -f %s > taosdemoperf.txt 2>&1" % self.generateJson()) tdSql.prepare()
self.createTableTime = self.getCMDOutput("grep 'Spent' taosdemoperf.txt | awk 'NR==1{print $2}'") buildPath = self.getBuildPath()
self.insertRecordsTime = self.getCMDOutput("grep 'Spent' taosdemoperf.txt | awk 'NR==2{print $2}'") if (buildPath == ""):
self.recordsPerSecond = self.getCMDOutput("grep 'Spent' taosdemoperf.txt | awk 'NR==2{print $16}'") tdLog.exit("taosdemo not found!")
else:
tdLog.info("taosdemo found in %s" % buildPath)
binPath = buildPath + "/build/bin/"
os.system(
"%staosdemo -f %s > taosdemoperf.txt 2>&1" %
(binPath, self.generateJson()))
self.createTableTime = self.getCMDOutput(
"grep 'Spent' taosdemoperf.txt | awk 'NR==1{print $2}'")
self.insertRecordsTime = self.getCMDOutput(
"grep 'Spent' taosdemoperf.txt | awk 'NR==2{print $2}'")
self.recordsPerSecond = self.getCMDOutput(
"grep 'Spent' taosdemoperf.txt | awk 'NR==2{print $16}'")
self.commitID = self.getCMDOutput("git rev-parse --short HEAD") self.commitID = self.getCMDOutput("git rev-parse --short HEAD")
delay = self.getCMDOutput("grep 'delay' taosdemoperf.txt | awk '{print $4}'") delay = self.getCMDOutput(
"grep 'delay' taosdemoperf.txt | awk '{print $4}'")
self.avgDelay = delay[:-4] self.avgDelay = delay[:-4]
delay = self.getCMDOutput("grep 'delay' taosdemoperf.txt | awk '{print $6}'") delay = self.getCMDOutput(
"grep 'delay' taosdemoperf.txt | awk '{print $6}'")
self.maxDelay = delay[:-4] self.maxDelay = delay[:-4]
delay = self.getCMDOutput("grep 'delay' taosdemoperf.txt | awk '{print $8}'") delay = self.getCMDOutput(
"grep 'delay' taosdemoperf.txt | awk '{print $8}'")
self.minDelay = delay[:-3] self.minDelay = delay[:-3]
os.system("[ -f taosdemoperf.txt ] && rm taosdemoperf.txt") os.system("[ -f taosdemoperf.txt ] && rm taosdemoperf.txt")
...@@ -131,12 +164,20 @@ class taosdemoPerformace: ...@@ -131,12 +164,20 @@ class taosdemoPerformace:
print("avg delay: %f" % float(self.avgDelay)) print("avg delay: %f" % float(self.avgDelay))
print("max delay: %f" % float(self.maxDelay)) print("max delay: %f" % float(self.maxDelay))
print("min delay: %f" % float(self.minDelay)) print("min delay: %f" % float(self.minDelay))
cursor.execute("insert into taosdemo_perf values(now, %f, %f, %f, '%s', %f, %f, %f)" % cursor.execute(
(float(self.createTableTime), float(self.insertRecordsTime), float(self.recordsPerSecond), self.commitID, float(self.avgDelay), float(self.maxDelay), float(self.minDelay))) "insert into taosdemo_perf values(now, %f, %f, %f, '%s', %f, %f, %f)" %
(float(
self.createTableTime), float(
self.insertRecordsTime), float(
self.recordsPerSecond), self.commitID, float(
self.avgDelay), float(
self.maxDelay), float(
self.minDelay)))
cursor.execute("drop database if exists %s" % self.insertDB) cursor.execute("drop database if exists %s" % self.insertDB)
cursor.close() cursor.close()
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
......
...@@ -36,7 +36,7 @@ class TDTestCase: ...@@ -36,7 +36,7 @@ class TDTestCase:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath): for root, dirs, files in os.walk(projPath):
if ("taosd" in files): if ("taosdemo" in files):
rootRealPath = os.path.dirname(os.path.realpath(root)) rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
...@@ -47,9 +47,9 @@ class TDTestCase: ...@@ -47,9 +47,9 @@ class TDTestCase:
tdSql.prepare() tdSql.prepare()
buildPath = self.getBuildPath() buildPath = self.getBuildPath()
if (buildPath == ""): if (buildPath == ""):
tdLog.exit("taosd not found!") tdLog.exit("taosdemo not found!")
else: else:
tdLog.info("taosd found in %s" % buildPath) tdLog.info("taosdemo found in %s" % buildPath)
binPath = buildPath + "/build/bin/" binPath = buildPath + "/build/bin/"
os.system("%staosdemo -y -t %d -n %d" % os.system("%staosdemo -y -t %d -n %d" %
(binPath, self.numberOfTables, self.numberOfRecords)) (binPath, self.numberOfTables, self.numberOfRecords))
......
...@@ -28,10 +28,27 @@ class TDTestCase: ...@@ -28,10 +28,27 @@ class TDTestCase:
self.numberOfTables = 10000 self.numberOfTables = 10000
self.numberOfRecords = 100 self.numberOfRecords = 100
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosdump" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
tdSql.execute("create table st(ts timestamp, c1 int, c2 nchar(10)) tags(t1 int, t2 binary(10))") tdSql.execute(
"create table st(ts timestamp, c1 int, c2 nchar(10)) tags(t1 int, t2 binary(10))")
tdSql.execute("create table t1 using st tags(1, 'beijing')") tdSql.execute("create table t1 using st tags(1, 'beijing')")
sql = "insert into t1 values" sql = "insert into t1 values"
currts = self.ts currts = self.ts
...@@ -46,15 +63,21 @@ class TDTestCase: ...@@ -46,15 +63,21 @@ class TDTestCase:
sql += "(%d, %d, 'nchar%d')" % (currts + i, i % 100, i % 100) sql += "(%d, %d, 'nchar%d')" % (currts + i, i % 100, i % 100)
tdSql.execute(sql) tdSql.execute(sql)
buildPath = self.getBuildPath()
if (buildPath == ""):
tdLog.exit("taosdump not found!")
else:
tdLog.info("taosdump found in %s" % buildPath)
binPath = buildPath + "/build/bin/"
os.system("rm /tmp/*.sql") os.system("rm /tmp/*.sql")
os.system("taosdump --databases db -o /tmp") os.system("%staosdump --databases db -o /tmp" % binPath)
tdSql.execute("drop database db") tdSql.execute("drop database db")
tdSql.query("show databases") tdSql.query("show databases")
tdSql.checkRows(0) tdSql.checkRows(0)
os.system("taosdump -i /tmp") os.system("%staosdump -i /tmp" % binPath)
tdSql.query("show databases") tdSql.query("show databases")
tdSql.checkRows(1) tdSql.checkRows(1)
......
...@@ -28,6 +28,22 @@ class TDTestCase: ...@@ -28,6 +28,22 @@ class TDTestCase:
self.numberOfTables = 1 self.numberOfTables = 1
self.numberOfRecords = 15000 self.numberOfRecords = 15000
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosdump" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
...@@ -44,14 +60,23 @@ class TDTestCase: ...@@ -44,14 +60,23 @@ class TDTestCase:
break break
tdSql.execute(sql) tdSql.execute(sql)
buildPath = self.getBuildPath()
if (buildPath == ""):
tdLog.exit("taosdump not found!")
else:
tdLog.info("taosdump found in %s" % buildPath)
binPath = buildPath + "/build/bin/"
os.system("rm /tmp/*.sql") os.system("rm /tmp/*.sql")
os.system("taosdump --databases db -o /tmp -B 32766 -L 1048576") os.system(
"%staosdump --databases db -o /tmp -B 32766 -L 1048576" %
binPath)
tdSql.execute("drop database db") tdSql.execute("drop database db")
tdSql.query("show databases") tdSql.query("show databases")
tdSql.checkRows(0) tdSql.checkRows(0)
os.system("taosdump -i /tmp") os.system("%staosdump -i /tmp" % binPath)
tdSql.query("show databases") tdSql.query("show databases")
tdSql.checkRows(1) tdSql.checkRows(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册