From f1454669713df0c9e2e93f8ecff00507ea50b613 Mon Sep 17 00:00:00 2001 From: wenzhouwww Date: Mon, 29 Nov 2021 19:29:18 +0800 Subject: [PATCH] change test case for CI for dump data into databases --- tests/pytest/client/taoshellCheckCase.py | 47 +++-- tests/pytest/fulltest.sh | 4 +- tests/pytest/tools/taosdumpTestNanoSupport.py | 166 +++++++----------- 3 files changed, 98 insertions(+), 119 deletions(-) diff --git a/tests/pytest/client/taoshellCheckCase.py b/tests/pytest/client/taoshellCheckCase.py index 936f7dfa15..f1e0c725dd 100644 --- a/tests/pytest/client/taoshellCheckCase.py +++ b/tests/pytest/client/taoshellCheckCase.py @@ -99,26 +99,41 @@ class TDTestCase: else: shutil.rmtree("./dumpdata") os.mkdir("./dumpdata") - - os.system(build_path + "/" + "taosdump -D test -o ./dumpdata") - sleep(2) - os.system("cd ./dumpdata && mv dbs.sql tables.sql") - os.system('sed -i "s/test/dumptest/g" `grep test -rl ./dumpdata`') - os.system(build_path + "/" + "taos -D ./dumpdata") - tdSql.query("select count(*) from dumptest.st") - tdSql.checkData(0, 0, 50) - - tdLog.info("========test other file name about tables.sql========") - os.system("rm -rf ./dumpdata/*") - os.system(build_path + "/" + "taosdump -D test -o ./dumpdata") - sleep(2) - os.system("cd ./dumpdata && mv dbs.sql table.sql") - os.system('sed -i "s/test/tt/g" `grep test -rl ./dumpdata`') + + # write data into sqls file + tables = ["CREATE DATABASE IF NOT EXISTS opendbtest REPLICA 1 QUORUM 1 DAYS\ + 10 KEEP 3650 CACHE 16 BLOCKS 16 MINROWS 100 MAXROWS 4096 FSYNC 3000 CACHELAST 0 COMP 2 PRECISION 'ms' UPDATE 0;", + + "CREATE TABLE IF NOT EXISTS opendbtest.cpus (ts TIMESTAMP, value DOUBLE) TAGS (author NCHAR(2), \ + department NCHAR(7), env NCHAR(4), hostname NCHAR(5), os NCHAR(6), production NCHAR(8), \ + team NCHAR(7), type NCHAR(10), useage NCHAR(7), workflow NCHAR(4));"] + with open("./dumpdata/tables.sql" ,"a") as f : + for item in tables: + f.write(item) + f.write("\n") + f.close() + + records = [ "CREATE TABLE IF NOT EXISTS opendbtest.tb USING opendbtest.cpus TAGS ('dd', 'Beijing', 'test', 'vm_7', 'ubuntu', 'taosdata', 'develop', 'usage_user', 'monitor', 'TIMI');", + "INSERT INTO opendbtest.tb VALUES (1420070400000, 59.078475);", + "INSERT INTO opendbtest.tb VALUES (1420070410000, 44.844490);", + "INSERT INTO opendbtest.tb VALUES (1420070420000, 34.796703);", + "INSERT INTO opendbtest.tb VALUES (1420070430000, 35.758099);", + "INSERT INTO opendbtest.tb VALUES (1420070440000, 51.502387);"] + + with open("./dumpdata/opendbtest.0.sql" ,"a") as f : + for item in records: + f.write(item) + f.write("\n") + f.close() + cmd = build_path + "/" + "taos -D ./dumpdata" out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE).stderr.read().decode("utf-8") if out.find("error:") >=0: print("===========expected error occured======") + tdSql.query("select value from opendbtest.tb") + tdSql.checkRows(5) + tdLog.info("====== check taos shell params ========") @@ -162,6 +177,7 @@ class TDTestCase: continue else: cmd = build_path + "/" + "taos -s \" insert into dbst.tb2 values(now ,2,2.0,'"+code+"','汉字"+code+"\')\"" + print(cmd) self.execute_cmd(cmd) @@ -192,6 +208,7 @@ class TDTestCase: for query in querys: cmd = build_path + "/" + "taos -s \""+query+"\"" self.execute_cmd(cmd) + print(cmd) def stop(self): tdSql.close() diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index effe48ab36..e057c5f542 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -182,7 +182,7 @@ python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoIns python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py -# disable due to taosdump don't support sql format. python3 test.py -f tools/taosdumpTestNanoSupport.py +python3 test.py -f tools/taosdumpTestNanoSupport.py # python3 ./test.py -f tsdb/tsdbComp.py @@ -305,7 +305,7 @@ python3 ./test.py -f client/client.py python3 ./test.py -f client/version.py python3 ./test.py -f client/alterDatabase.py python3 ./test.py -f client/noConnectionErrorTest.py -# disable due to taosdump don't support sql format. python3 ./test.py -f client/taoshellCheckCase.py +python3 ./test.py -f client/taoshellCheckCase.py # python3 test.py -f client/change_time_1_1.py # python3 test.py -f client/change_time_1_2.py diff --git a/tests/pytest/tools/taosdumpTestNanoSupport.py b/tests/pytest/tools/taosdumpTestNanoSupport.py index 727690c6e6..81e3159346 100644 --- a/tests/pytest/tools/taosdumpTestNanoSupport.py +++ b/tests/pytest/tools/taosdumpTestNanoSupport.py @@ -143,59 +143,41 @@ class TDTestCase: '%staosdump --databases timedb1 -S 1625068810000000000 -o ./taosdumptest/dumptmp3 ' % binPath) - # replace strings to dump in databases - os.system( - "sed -i \"s/timedb1/dumptmp1/g\" `grep timedb1 -rl ./taosdumptest/dumptmp1`") - os.system( - "sed -i \"s/timedb1/dumptmp2/g\" `grep timedb1 -rl ./taosdumptest/dumptmp2`") - os.system( - "sed -i \"s/timedb1/dumptmp3/g\" `grep timedb1 -rl ./taosdumptest/dumptmp3`") - - os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + tdSql.execute("drop database timedb1") os.system("%staosdump -i ./taosdumptest/dumptmp2" % binPath) - os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) - - # dump data and check for taosdump - tdSql.query("select count(*) from dumptmp1.st") - tdSql.checkData(0, 0, 1000) - - tdSql.query("select count(*) from dumptmp2.st") + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 510) - tdSql.query("select count(*) from dumptmp3.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 900) + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") + tdSql.checkData(0, 0, 1000) + # check data origin_res = tdSql.getResult("select * from timedb1.st") - dump_res = tdSql.getResult("select * from dumptmp1.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + dump_res = tdSql.getResult("select * from timedb1.st") if origin_res == dump_res: tdLog.info("test nano second : dump check data pass for all data!") else: tdLog.info( "test nano second : dump check data failed for all data!") - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000000000 and ts <= 1625068860000000000") - dump_res = tdSql.getResult("select * from dumptmp2.st") - if origin_res == dump_res: - tdLog.info(" test nano second : dump check data pass for data! ") - else: - tdLog.info(" test nano second : dump check data failed for data !") - - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000000000 ") - dump_res = tdSql.getResult("select * from dumptmp3.st") - if origin_res == dump_res: - tdLog.info(" test nano second : dump check data pass for data! ") - else: - tdLog.info(" test nano second : dump check data failed for data !") - # us second support test case os.system("rm -rf ./taosdumptest/") - tdSql.execute("drop database if exists dumptmp1") - tdSql.execute("drop database if exists dumptmp2") - tdSql.execute("drop database if exists dumptmp3") + tdSql.execute("drop database if exists timedb1") + if not os.path.exists("./taosdumptest/tmp1"): os.makedirs("./taosdumptest/dumptmp1") @@ -228,55 +210,44 @@ class TDTestCase: '%staosdump --databases timedb1 -S 1625068810000000 -o ./taosdumptest/dumptmp3 ' % binPath) - os.system( - "sed -i \"s/timedb1/dumptmp1/g\" `grep timedb1 -rl ./taosdumptest/dumptmp1`") - os.system( - "sed -i \"s/timedb1/dumptmp2/g\" `grep timedb1 -rl ./taosdumptest/dumptmp2`") - os.system( - "sed -i \"s/timedb1/dumptmp3/g\" `grep timedb1 -rl ./taosdumptest/dumptmp3`") - os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) os.system("%staosdump -i ./taosdumptest/dumptmp2" % binPath) os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) - tdSql.query("select count(*) from dumptmp1.st") - tdSql.checkData(0, 0, 1000) - - tdSql.query("select count(*) from dumptmp2.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp2" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 510) - tdSql.query("select count(*) from dumptmp3.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 900) - origin_res = tdSql.getResult("select * from timedb1.st") - dump_res = tdSql.getResult("select * from dumptmp1.st") - if origin_res == dump_res: - tdLog.info("test us second : dump check data pass for all data!") - else: - tdLog.info("test us second : dump check data failed for all data!") - - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000000 and ts <= 1625068860000000") - dump_res = tdSql.getResult("select * from dumptmp2.st") - if origin_res == dump_res: - tdLog.info(" test us second : dump check data pass for data! ") - else: - tdLog.info(" test us second : dump check data failed for data!") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") + tdSql.checkData(0, 0, 1000) - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000000 ") - dump_res = tdSql.getResult("select * from dumptmp3.st") + # check data + origin_res = tdSql.getResult("select * from timedb1.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + dump_res = tdSql.getResult("select * from timedb1.st") if origin_res == dump_res: - tdLog.info(" test us second : dump check data pass for data! ") + tdLog.info("test micro second : dump check data pass for all data!") else: - tdLog.info(" test us second : dump check data failed for data! ") + tdLog.info( + "test micro second : dump check data failed for all data!") # ms second support test case os.system("rm -rf ./taosdumptest/") - tdSql.execute("drop database if exists dumptmp1") - tdSql.execute("drop database if exists dumptmp2") - tdSql.execute("drop database if exists dumptmp3") + tdSql.execute("drop database if exists timedb1") if not os.path.exists("./taosdumptest/tmp1"): os.makedirs("./taosdumptest/dumptmp1") @@ -309,48 +280,39 @@ class TDTestCase: '%staosdump --databases timedb1 -S 1625068810000 -o ./taosdumptest/dumptmp3 ' % binPath) - os.system( - "sed -i \"s/timedb1/dumptmp1/g\" `grep timedb1 -rl ./taosdumptest/dumptmp1`") - os.system( - "sed -i \"s/timedb1/dumptmp2/g\" `grep timedb1 -rl ./taosdumptest/dumptmp2`") - os.system( - "sed -i \"s/timedb1/dumptmp3/g\" `grep timedb1 -rl ./taosdumptest/dumptmp3`") - os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) os.system("%staosdump -i ./taosdumptest/dumptmp2" % binPath) os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) - tdSql.query("select count(*) from dumptmp1.st") - tdSql.checkData(0, 0, 1000) - - tdSql.query("select count(*) from dumptmp2.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp2" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 510) - tdSql.query("select count(*) from dumptmp3.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp3" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") tdSql.checkData(0, 0, 900) - origin_res = tdSql.getResult("select * from timedb1.st") - dump_res = tdSql.getResult("select * from dumptmp1.st") - if origin_res == dump_res: - tdLog.info("test ms second : dump check data pass for all data!") - else: - tdLog.info("test ms second : dump check data failed for all data!") - - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000 and ts <= 1625068860000") - dump_res = tdSql.getResult("select * from dumptmp2.st") - if origin_res == dump_res: - tdLog.info(" test ms second : dump check data pass for data! ") - else: - tdLog.info(" test ms second : dump check data failed for data!") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + tdSql.query("select count(*) from timedb1.st") + tdSql.checkData(0, 0, 1000) - origin_res = tdSql.getResult( - "select * from timedb1.st where ts >=1625068810000 ") - dump_res = tdSql.getResult("select * from dumptmp3.st") + # check data + origin_res = tdSql.getResult("select * from timedb1.st") + tdSql.execute("drop database timedb1") + os.system("%staosdump -i ./taosdumptest/dumptmp1" % binPath) + # dump data and check for taosdump + dump_res = tdSql.getResult("select * from timedb1.st") if origin_res == dump_res: - tdLog.info(" test ms second : dump check data pass for data! ") + tdLog.info("test million second : dump check data pass for all data!") else: - tdLog.info(" test ms second : dump check data failed for data! ") + tdLog.info( + "test million second : dump check data failed for all data!") os.system("rm -rf ./taosdumptest/") os.system("rm -rf ./dump_result.txt") -- GitLab