From dd5b5474045b6910c1d72a8be19b682b2fa55871 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Mon, 5 Aug 2024 09:48:02 +0800 Subject: [PATCH 1/4] test:add concurrency test cases for executing the taos -k command line. --- tests/system-test/0-others/taosShell.py | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index 5158c3dfac..dc741cbfcf 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -16,6 +16,9 @@ from util.sql import * from util.cases import * from util.dnodes import * +import subprocess +import threading + def taos_command (buildPath, key, value, expectString, cfgDir, sqlString='', key1='', value1=''): if len(key) == 0: tdLog.exit("taos test key is null!") @@ -129,6 +132,34 @@ class TDTestCase: buildPath = root[:len(root) - len("/build/bin")] break return buildPath + def run_command(self, commands): + self.taos_output = [] + count = 0 + while count < 2: + print(f"count: {count}") + value = subprocess.getoutput(f"nohup {commands} &") + print(f"value: {value}") + self.taos_output.append(value) + count += 1 + return self.taos_output + + def taos_thread_repeat_k(self, run_command, commands, threads_num=10, output=[]): + threads = [] + taos_output = self.taos_output + threads_num = 20 + + for id in range(threads_num): + #threads.append(Process(target=cloud_consumer, args=(id,))) + threads.append(threading.Thread(target=run_command, args=(commands,))) + for tr in threads: + tr.start() + for tr in threads: + tr.join() + + for value in taos_output: + if "crash" in value: + print(f"command: {commands} crash") + exit(1) def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() @@ -445,6 +476,12 @@ class TDTestCase: tdSql.query('drop database %s'%newDbName) + commands = f"taos -k -c {cfgPath}" + output = self.run_command(commands) + os.sys + self.taos_thread_repeat_k(self.run_command, commands, 10, output) + # os.system("python 0-others/repeat_taos_k.py") + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") From 1a871e0292dbaee438b023ae803e04862d5c8e08 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Mon, 5 Aug 2024 11:01:32 +0800 Subject: [PATCH 2/4] test:add concurrency test cases for executing the taos -k command line. --- tests/system-test/0-others/taosShell.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index dc741cbfcf..549231fc6c 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -111,7 +111,7 @@ class TDTestCase: updatecfgDict["fqdn"] = hostname print ("===================: ", updatecfgDict) - + taos_output = [] def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") @@ -119,7 +119,6 @@ class TDTestCase: def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) - if ("community" in selfPath): projPath = selfPath[:selfPath.find("community")] else: @@ -133,21 +132,17 @@ class TDTestCase: break return buildPath def run_command(self, commands): - self.taos_output = [] + count = 0 while count < 2: - print(f"count: {count}") + # print(f"count: {count}") value = subprocess.getoutput(f"nohup {commands} &") - print(f"value: {value}") + # print(f"value: {value}") self.taos_output.append(value) count += 1 - return self.taos_output - def taos_thread_repeat_k(self, run_command, commands, threads_num=10, output=[]): threads = [] - taos_output = self.taos_output - threads_num = 20 - + taos_output = self.taos_output for id in range(threads_num): #threads.append(Process(target=cloud_consumer, args=(id,))) threads.append(threading.Thread(target=run_command, args=(commands,))) @@ -155,11 +150,9 @@ class TDTestCase: tr.start() for tr in threads: tr.join() - for value in taos_output: if "crash" in value: - print(f"command: {commands} crash") - exit(1) + tdLog.exit(f"command: {commands} crash") def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() @@ -479,7 +472,7 @@ class TDTestCase: commands = f"taos -k -c {cfgPath}" output = self.run_command(commands) os.sys - self.taos_thread_repeat_k(self.run_command, commands, 10, output) + self.taos_thread_repeat_k(self.run_command, commands, 100, output) # os.system("python 0-others/repeat_taos_k.py") def stop(self): From de572c8c0fee49f709007eb14e015fe4682b4709 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Mon, 5 Aug 2024 11:02:23 +0800 Subject: [PATCH 3/4] test:add concurrency test cases for executing the taos -k command line. --- tests/system-test/0-others/taosShell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index 549231fc6c..b046785903 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -140,6 +140,7 @@ class TDTestCase: # print(f"value: {value}") self.taos_output.append(value) count += 1 + def taos_thread_repeat_k(self, run_command, commands, threads_num=10, output=[]): threads = [] taos_output = self.taos_output From 0ffef4947bb11912a98aaefde7505083f222f7f9 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Mon, 5 Aug 2024 11:08:51 +0800 Subject: [PATCH 4/4] test:add concurrency test cases for executing the taos -k command line. --- tests/system-test/0-others/taosShell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index b046785903..91e9f2fb89 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -470,7 +470,7 @@ class TDTestCase: tdSql.query('drop database %s'%newDbName) - commands = f"taos -k -c {cfgPath}" + commands = f"{buildPath}/taos -k -c {cfgPath}" output = self.run_command(commands) os.sys self.taos_thread_repeat_k(self.run_command, commands, 100, output)