diff --git a/tests/auto_crash_gen_script/auto_crash_gen_script.py b/tests/auto_crash_gen_script/auto_crash_gen_script.py new file mode 100644 index 0000000000000000000000000000000000000000..547526c8ccaa710f88d4ad2d64bd1d1cd6d31e9b --- /dev/null +++ b/tests/auto_crash_gen_script/auto_crash_gen_script.py @@ -0,0 +1,273 @@ +################################################################### +# Copyright (c) 2020 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +import os ,sys +import random +import argparse +import subprocess +import time + +# set path about run instance + +core_path = '/home/coredump/' +base_dir = os.path.dirname(os.path.realpath(__file__)) +if base_dir.find("community")>0: + repo = "community" +elif base_dir.find("TDengine")>0: + repo = "TDengine" +else: + repo ="TDengine" +print("base_dir:",base_dir) +home_dir = base_dir[:base_dir.find(repo)] +print("home_dir:",home_dir) +run_dir = os.path.join(home_dir,'run_dir') +run_dir = os.path.abspath(run_dir) +print("run dir is set at :",run_dir) +if not os.path.exists(run_dir): + os.mkdir(run_dir) +run_log_file = run_dir+'/crash_gen_run.log' +crash_gen_cmds_file = os.path.join(run_dir, 'crash_gen_cmds.sh') +exit_status_logs = os.path.join(run_dir, 'crash_exit.log') + +def get_path(): + buildPath='' + 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 ("taosd" 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 random_args(args_list): + nums_args_list = ["--max-dbs","--num-replicas","--num-dnodes","--max-steps","--num-threads",] # record int type arguments + bools_args_list = ["--auto-start-service" , "--debug","--run-tdengine","--ignore-errors","--track-memory-leaks","--larger-data","--mix-oos-data","--dynamic-db-table-names", + "--per-thread-db-connection","--record-ops","--verify-data","--use-shadow-db","--continue-on-exception" + ] # record bool type arguments + strs_args_list = ["--connector-type"] # record str type arguments + + args_list["--auto-start-service"]= True + args_list["--continue-on-exception"]=True + # connect_types=['native','rest','mixed'] # restful interface has change ,we should trans dbnames to connection or change sql such as "db.test" + connect_types=['native'] + # args_list["--connector-type"]=connect_types[random.randint(0,2)] + args_list["--connector-type"]= connect_types[0] + args_list["--max-dbs"]= random.randint(1,10) + + dnodes = [1,3] # set single dnodes; + + args_list["--num-dnodes"]= random.sample(dnodes,1)[0] + args_list["--num-replicas"]= random.randint(1,args_list["--num-dnodes"]) + args_list["--debug"]=False + args_list["--per-thread-db-connection"]=True + args_list["--track-memory-leaks"]=False + + num = random.randint(1, 10) # set --track-memory-leaks randomly + if num > 8 : + args_list["--track-memory-leaks"]=True + + + args_list["--max-steps"]=random.randint(300,500) + + threads = [32,64,128] + args_list["--num-threads"]=random.sample(threads,1)[0] #$ debug + args_list["--ignore-errors"]=[] ## can add error codes for detail + + + args_list["--run-tdengine"]= False + args_list["--use-shadow-db"]= False + args_list["--dynamic-db-table-names"]= False + args_list["--verify-data"]= False + args_list["--record-ops"] = False + + for key in bools_args_list: + set_bool_value = [True,False] + if key == "--auto-start-service" : + continue + elif key =="--run-tdengine": + continue + elif key == "--ignore-errors": + continue + elif key == "--debug": + continue + elif key == "--per-thread-db-connection": + continue + elif key == "--continue-on-exception": + continue + elif key == "--use-shadow-db": + continue + elif key =="--track-memory-leaks": + continue + elif key == "--dynamic-db-table-names": + continue + elif key == "--verify-data": + continue + elif key == "--record-ops": + continue + else: + args_list[key]=set_bool_value[random.randint(0,1)] + return args_list + +def limits(args_list): + if args_list["--use-shadow-db"]==True: + if args_list["--max-dbs"] > 1: + print("Cannot combine use-shadow-db with max-dbs of more than 1 ,set max-dbs=1") + args_list["--max-dbs"]=1 + else: + pass + + elif args_list["--num-replicas"]==0: + print(" make sure num-replicas is at least 1 ") + args_list["--num-replicas"]=1 + elif args_list["--num-replicas"]==1: + pass + + elif args_list["--num-replicas"]>1: + if not args_list["--auto-start-service"]: + print("it should be deployed by crash_gen auto-start-service for multi replicas") + + else: + pass + + return args_list + +def get_cmds(args_list): + build_path = get_path() + if repo == "community": + crash_gen_path = build_path[:-5]+"community/tests/pytest/" + elif repo == "TDengine": + crash_gen_path = build_path[:-5]+"/tests/pytest/" + else: + pass + + bools_args_list = ["--auto-start-service" , "--debug","--run-tdengine","--ignore-errors","--track-memory-leaks","--larger-data","--mix-oos-data","--dynamic-db-table-names", + "--per-thread-db-connection","--record-ops","--verify-data","--use-shadow-db","--continue-on-exception"] + arguments = "" + for k ,v in args_list.items(): + if k == "--ignore-errors": + if v: + arguments+=(k+"="+str(v)+" ") + else: + arguments+="" + elif k in bools_args_list and v==True: + arguments+=(k+" ") + elif k in bools_args_list and v==False: + arguments+="" + else: + arguments+=(k+"="+str(v)+" ") + crash_gen_cmd = 'cd %s && ./crash_gen.sh %s '%(crash_gen_path ,arguments) + return crash_gen_cmd + +def run_crash_gen(crash_cmds,result_file): + os.system('echo "%s">>%s'%(crash_cmds,crash_gen_cmds_file)) + os.system("cp %s %s"%(crash_gen_cmds_file, core_path)) + os.system("%s>>%s"%(crash_cmds,result_file)) + +def check_status(result_file): + run_code = subprocess.Popen("tail -n 50 %s"%result_file, shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + os.system("tail -n 50 %s>>%s"%(result_file,exit_status_logs)) + mem_status = check_memory(run_dir) + if mem_status >0: + return mem_status + if "Crash_Gen is now exiting with status code: 1" in run_code: + return 1 + elif "Crash_Gen is now exiting with status code: 0" in run_code: + return 0 + else: + return 2 + +def check_memory(run_dir): + ''' + invalid read, invalid write + ''' + mem_report_path = os.path.join(run_dir , "reporter") + if not os.path.exists(mem_report_path): + os.mkdir(mem_report_path) + status = 0 + stderr_files = subprocess.Popen("find %s -name \"stderr.log\" "%run_dir , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + stderr_list = stderr_files.split("\n")[:-1] + for stderr_file in stderr_list: + print(stderr_file) + grep_res = subprocess.Popen("grep -i 'Invalid read' %s "%stderr_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + dnode_name = stderr_file.split("/")[-3] + back_path = os.path.join(core_path,"reporter",dnode_name) + if not os.path.exists(back_path): + os.system("mkdir -p %s"%back_path) + + if grep_res: + os.system("cp %s %s"%(stderr_file , back_path)) + status = 4 + break + + grep_res = subprocess.Popen("grep -i 'Invalid write' %s "%stderr_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + if grep_res: + status = 4 + os.system("cp %s %s"%(stderr_file , back_path)) + break + return status + +def main(): + args_list = {"--auto-start-service":False ,"--max-dbs":0,"--connector-type":"native","--debug":False,"--run-tdengine":False,"--ignore-errors":[], + "--num-replicas":1 ,"--track-memory-leaks":False , "--larger-data":False, "--mix-oos-data":False, "--dynamic-db-table-names":False,"--num-dnodes":1, + "--per-thread-db-connection":False , "--record-ops":False , "--max-steps":100, "--num-threads":10, "--verify-data":False,"--use-shadow-db":False , + "--continue-on-exception":False } + + build_path = get_path() + os.system("pip3 install taospy") + if repo =="community": + crash_gen_path = build_path[:-5]+"community/tests/pytest/" + elif repo =="TDengine": + crash_gen_path = build_path[:-5]+"/tests/pytest/" + else: + pass + print(crash_gen_path) + if os.path.exists(crash_gen_path+"crash_gen.sh"): + print(" make sure crash_gen.sh is ready") + else: + print( " crash_gen.sh is not exists ") + sys.exit(1) + + # set value args + + args = random_args(args_list) + args = limits(args) + crash_cmds = get_cmds(args) + crash_cmds= crash_cmds+"--set-path="+"%s"%run_dir + # clean run_dir + os.system('rm -rf %s'%run_dir ) + if not os.path.exists(run_dir): + os.mkdir(run_dir) + print(crash_cmds) + run_crash_gen(crash_cmds,run_log_file) + status = check_status(run_log_file) + + print("exit status : ", status) + if status ==4: + print('======== crash_gen found memory bugs at reporter ========') + if status >0: + print('======== crash_gen run failed and not exit as expected ========') + else: + print('======== crash_gen run sucess and exit as expected ========') + exit(status) + + +if __name__ == '__main__': + main() + + diff --git a/tests/system-test/abnormal/Always_alter_schema.py b/tests/system-test/abnormal/Always_alter_schema.py deleted file mode 100644 index 175204a791b0504fa7db3f47c15ade77a113e9ae..0000000000000000000000000000000000000000 --- a/tests/system-test/abnormal/Always_alter_schema.py +++ /dev/null @@ -1,162 +0,0 @@ -################################################################### -# Copyright (c) 2020 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -from http import client -import taos -import time - -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * -import random - -class TDTestCase: - def __init__(self): - self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record - self.num = 10 - self.Loop = 10 - self.loop_alter = 100 - - def caseDescription(self): - - ''' - case1 : this is an abnormal case for always change schema - ''' - return - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - - def run(self): - - # Loop - tdSql.execute("drop database if exists testdb") - tdSql.execute("create database testdb") - tdSql.execute("use testdb") - tdSql.execute("create stable testdb.st (ts timestamp , value int) tags (ind int)") - tdSql.query("describe testdb.st") - - # insert data - for cur in range(self.num): - tdSql.execute("insert into tb_%d using st tags(%d) values(%d, %d)"%(cur,cur, self.ts+1000*cur,cur)) - tdSql.execute("insert into tb_set using st tags(%d) values(%d, %d)"%(cur,self.ts+1000*cur,cur)) - - client_0 = taos.connect().cursor() # global conn - - client_1 = taos.connect().cursor() - client_2 = taos.connect().cursor() - - add_tag_list = [] - for i in range(self.loop_alter): - sql= "alter stable testdb.st add tag new_tag%d int"%i - add_tag_list.append(sql) - - change_tag_list = [] - for i in range(self.loop_alter+1): - sql = " alter stable testdb.st change tag new_tag%d new_tag_%d"%(i,i) - change_tag_list.append(sql) - - set_tag_list = [] - for i in range(self.loop_alter): - sql = "alter table testdb.tb_set set tag new_tag_%d=%d"%(i,i*10) - set_tag_list.append(sql) - - drop_tag_list = [] - for i in range(self.loop_alter): - sql = "alter stable testdb.st drop tag new_tag_%d"%(i) - drop_tag_list.append(sql) - - for i in range(self.loop_alter): - add_sql = add_tag_list[i] - change_sql = change_tag_list[i] - set_sql = set_tag_list[i] - drop_sql = drop_tag_list[i] - - execute_list= [add_sql,change_sql,set_sql,drop_sql] - - for ind,sql in enumerate(execute_list): - if sql ==drop_sql: - if i%5 !=0: - continue - else: - pass - - if ind%3==0: - # client_0.execute("reset query cache") - client_0.execute(sql) - print(" client_0 runing sqls : %s" %sql ) - elif ind%3==1: - # client_1.execute("reset query cache") - client_1.execute(sql) - print(" client_1 runing sqls : %s" %sql ) - elif ind%3==2: - # client_2.execute("reset query cache") - client_2.execute(sql) - print(" client_2 runing sqls : %s" %sql ) - else: - client_0.execute(sql) - print(" client_0 runing sqls : %s" %sql ) - - query_sqls = ["select count(*) from testdb.st group by ind", - "describe testdb.st", - "select count(*) from testdb.st group by tbname"] - reset_sql = "reset query cache" - - if i%10 ==0: - tdSql.execute(reset_sql) - client_0.execute(reset_sql) - client_1.execute(reset_sql) - client_2.execute(reset_sql) - - for sql in query_sqls: - if sql =="describe testdb.st": - print("==========================\n") - print("==========describe=======\n") - print("==========================\n") - client_0.execute(sql) - res = client_0.fetchall() - print("client 0 res :", res) if res else print("empty") - - client_1.execute(sql) - res = client_0.fetchall() - print("client 1 res :", res) if res else print("empty") - - client_2.execute(sql) - res = client_2.fetchall() - print("client 2 res :", res) if res else print("empty") - else: - client_0.execute(sql) - client_1.execute(sql) - client_2.execute(sql) - - tdLog.notice("===== this is the %d_th loop alter tags is going now ===="%i ) - - - - - - client_1.close() - client_2.close() - - client_0.close() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/abnormal/Loop_restart_and_kill.py b/tests/system-test/abnormal/Loop_restart_and_kill.py deleted file mode 100644 index 8ac1f7c8f1f7e7b8bb15ffb7549370ec61438165..0000000000000000000000000000000000000000 --- a/tests/system-test/abnormal/Loop_restart_and_kill.py +++ /dev/null @@ -1,89 +0,0 @@ -################################################################### -# Copyright (c) 2020 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- -import taos -import time - -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def __init__(self): - self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record - self.num = 10 - self.Loop = 100 - - def caseDescription(self): - - ''' - case1 : this is an abnormal case for loop restart taosd - and basic this query ,it will run 4 client to change schema ,run always ; - ''' - return - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def basic_insert(self): - tdSql.execute("create database if not exists testdb") - tdSql.execute("use testdb") - tdSql.execute("create stable st (ts timestamp , value int) tags (ind int)") - for i in range(self.num): - tdSql.execute("insert into sub_%s using st tags(%d) values (%d , %d );"%(str(i),i,self.ts+10000*i,i)) - - def basic_query(self): - for i in range(self.num): - tdSql.query("select count(*) from testdb.sub_%s"%str(i)) - tdSql.checkData(0,0,1) - tdSql.query("select count(*) from testdb.st") - tdSql.checkRows(1) - - - def run(self): - - # Loop - - for loop_step in range(self.Loop): - - # run basic query and insert - # kill all - os.system("ps -aux |grep 'taosd' |awk '{print $2}'|xargs kill -9 >/dev/null 2>&1") - tdDnodes.start(1) - if loop_step ==0: - self.basic_insert() - else: - tdSql.execute("insert into sub_10 using st tags(10) values(now ,10)") - - # another client - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - os.system('taos -s "select count(*) from testdb.sub_100;"') - - self.basic_query() - sleep(2) - tdDnodes.stopAll() - - - tdLog.info(" this is the %s_th loop restart taosd going " % loop_step) - - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/abnormal/Loop_restart_database_alter.py b/tests/system-test/abnormal/Loop_restart_database_alter.py deleted file mode 100644 index d2721fa15d3f309bc91d764356e3f1fb3b1d354a..0000000000000000000000000000000000000000 --- a/tests/system-test/abnormal/Loop_restart_database_alter.py +++ /dev/null @@ -1,160 +0,0 @@ -################################################################### -# Copyright (c) 2020 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -from http import client -import taos -import time - -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * -import random - -class TDTestCase: - def __init__(self): - self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record - self.num = 10 - self.Loop = 100 - global client - - def caseDescription(self): - - ''' - case1 : this is an abnormal case for loop restart taosd - between restart taosd ,there is an query and is insert is going on - ''' - return - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - - def run(self): - - # Loop - tdSql.execute("drop database if exists testdb") - client = taos.connect().cursor() # global conn - - # tdSql.execute("create database testdb") - # tdSql.execute("create stable testdb.st (ts timestamp , value int) tags (ind int)") - # tdSql.query("describe testdb.st") - # result = tdSql.getResult("describe testdb.st") - # print(result) - # tdSql.execute("alter stable testdb.st add tag new_tags int") - # result = tdSql.getResult("describe testdb.st") - # print(result) - # tdSql.execute("alter stable testdb.st change tag new_tags alter_tag") - # result = tdSql.getResult("describe testdb.st") - # print(result) - - - for loop_step in range(self.Loop): - - # run basic query and insert - # kill all - os.system("ps -aux |grep 'taosd' |awk '{print $2}'|xargs kill -9 >/dev/null 2>&1") - tdDnodes.start(1) - - tdSql.execute("create database if not exists testdb") - tdSql.execute("use testdb") - - if loop_step <1: - tdSql.execute("create stable st (ts timestamp , value int) tags (ind int)") - - tdSql.execute("create stable st%d (ts timestamp , value int) tags (ind int)"%loop_step) - for cur in range(self.num): - tdSql.execute("insert into tb_%d using st%d tags(%d) values(now, %d)"%(loop_step,loop_step,loop_step, cur)) - - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - os.system('taos -s "select count(*) from testdb.sub_100;"') - os.system('taos -s "describe testdb.sub_100;"') - os.system('show databases\G') - # another client - client_1 = taos.connect().cursor() - client_2 = taos.connect().cursor() - - alter_dict = {"days" : int(random.randint(1,5)) , - "keep":int(random.randint(10,20)) , - "precision":"ns", - "blocks" : int(random.randint(1,6)*2), - "quorum": int(random.randint(0,3)), - "comp":int(random.randint(0,3)), - "minrows":int(random.randint(1,3)*100), - "replica":int(random.randint(1,3)) - } - alter_list = ['days', 'keep', 'precision', 'blocks', 'quorum', 'comp', 'minrows', 'replica'] - random_key = random.sample(alter_list, 1)[0] - - sql = "alter database {} {} {}".format("testdb", random_key, alter_dict[random_key]) - - for alter_db in range(100): - alter_list = ['days', 'keep', 'precision', 'blocks', 'quorum', 'comp', 'minrows', 'replica'] - random_key = random.sample(alter_list, 1)[0] - sql = "alter database {} {} {}".format("testdb", random_key, alter_dict[random_key]) - - if alter_db%3==0: - # client_0.execute("reset query cache") - try: - client.execute(sql) - client.fetchall() - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - except : - pass - print(" client runing sqls : %s" %sql ) - elif alter_db%3==1: - # client_1.execute("reset query cache") - try: - client_1.execute(sql) - client_1.fetchall() - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - except : - pass - print(" client_1 runing sqls : %s" %sql ) - elif alter_db%3==2: - try: - # client_2.execute("reset query cache") - client_2.execute(sql) - client_2.fetchall() - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - except: - pass - print(" client_2 runing sqls : %s" %sql ) - else: - try: - client.execute(sql) - client.fetchall() - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - except: - pass - print(" client runing sqls : %s" %sql ) - os.system("taos -s 'show databases;'") - - sleep(2) - tdDnodes.stopAll() - - tdLog.notice(" this is the %s_th loop restart taosd going " % loop_step) - - client_1.close() - client_2.close() - - client.close() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/abnormal/Loop_restart_schema_alter.py b/tests/system-test/abnormal/Loop_restart_schema_alter.py deleted file mode 100644 index 63b4b645af4b73ab7056a07b4566ccdc682f986f..0000000000000000000000000000000000000000 --- a/tests/system-test/abnormal/Loop_restart_schema_alter.py +++ /dev/null @@ -1,139 +0,0 @@ -################################################################### -# Copyright (c) 2020 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -from http import client -import taos -import time - -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * -import random - -class TDTestCase: - def __init__(self): - self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record - self.num = 10 - self.Loop = 100 - global client - - def caseDescription(self): - - ''' - case1 : this is an abnormal case for loop restart taosd - between restart taosd ,there is an query and is insert is going on - ''' - return - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - - def run(self): - - # Loop - tdSql.execute("drop database if exists testdb") - client = taos.connect().cursor() # global conn - - # tdSql.execute("create database testdb") - # tdSql.execute("create stable testdb.st (ts timestamp , value int) tags (ind int)") - # tdSql.query("describe testdb.st") - # result = tdSql.getResult("describe testdb.st") - # print(result) - # tdSql.execute("alter stable testdb.st add tag new_tags int") - # result = tdSql.getResult("describe testdb.st") - # print(result) - # tdSql.execute("alter stable testdb.st change tag new_tags alter_tag") - # result = tdSql.getResult("describe testdb.st") - # print(result) - - - for loop_step in range(self.Loop): - - # run basic query and insert - # kill all - os.system("ps -aux |grep 'taosd' |awk '{print $2}'|xargs kill -9 >/dev/null 2>&1") - tdDnodes.start(1) - - tdSql.execute("create database if not exists testdb") - tdSql.execute("use testdb") - - if loop_step <1: - tdSql.execute("create stable st (ts timestamp , value int) tags (ind int)") - - tdSql.execute("create stable st%d (ts timestamp , value int) tags (ind int)"%loop_step) - for cur in range(self.num): - tdSql.execute("insert into tb_%d using st%d tags(%d) values(%d, %d)"%(loop_step,loop_step,loop_step, self.ts+1000*cur,cur)) - - os.system('taos -s "insert into testdb.sub_100 using testdb.st tags(100) values(now ,100);"') - os.system('taos -s "select count(*) from testdb.sub_100;"') - os.system('taos -s "describe testdb.sub_100;"') - # another client - client_1 = taos.connect().cursor() - client_2 = taos.connect().cursor() - - alter_tag = [ - " alter stable testdb.st%d add tag new_tags int "%loop_step, - " alter stable testdb.st%d change tag new_tags alter_tag"%loop_step, - " alter stable testdb.st%d drop tag alter_tag"%loop_step, - "ALTER TABLE testdb.sub_100 SET TAG ind=%d"%(loop_step*10) - ] - print(alter_tag[0]) - client_1.execute(alter_tag[0]) - os.system('taos -s "%s; describe testdb.sub_100;select ind from testdb.sub_100;"'% alter_tag[3] ) - - # clinet1 - os.system('taos -s "%s; describe testdb.sub_100;select ind from testdb.sub_100;"'% alter_tag[3] ) - # client_1.execute("reset query cache;") - client_1.execute(" describe testdb.st%d"%loop_step) - res = client_1.fetchall() - - # clinet2 - os.system('taos -s "%s; describe testdb.sub_100;select ind from testdb.sub_100;"'% alter_tag[3] ) - - print(alter_tag[1]) - client_2.execute(alter_tag[1]) - # client_2.execute("reset query cache") - client_2.execute("describe testdb.st%d"%loop_step) - res = client_2.fetchall() - - client_2.execute("select * from testdb.st%d"%loop_step) - res = client_2.fetchall() - - client.execute("show databases;") - # client.execute("reset query cache") - client.execute("describe testdb.st%d"%loop_step) - print(alter_tag[2]) - client.execute(alter_tag[2]) - res = client.fetchall_row() - - - sleep(2) - tdDnodes.stopAll() - - tdLog.notice(" this is the %s_th loop restart taosd going " % loop_step) - - client_1.close() - client_2.close() - - client.close() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase())