From cc62c400c6b697d7c0f89bdaa731224c879d534b Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 16 Aug 2023 19:13:24 +0800 Subject: [PATCH] fix: tmq drop/common python script on windows --- tests/system-test/7-tmq/tmqCommon.py | 30 ++++++++++++++++------ tests/system-test/7-tmq/tmqDropConsumer.py | 5 +++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/system-test/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py index 3ea8273e7f..c1583be009 100644 --- a/tests/system-test/7-tmq/tmqCommon.py +++ b/tests/system-test/7-tmq/tmqCommon.py @@ -578,18 +578,32 @@ class TMQCom: tdLog.info("wait subscriptions exit for %d s"%wait_cnt) def killProcesser(self, processerName): - killCmd = ( - "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" - % processerName - ) - - psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % processerName - processID = subprocess.check_output(psCmd, shell=True) + if platform.system().lower() == 'windows': + killCmd = ("wmic process where name=\"%s.exe\" call terminate > NUL 2>&1" % processerName) + psCmd = ("wmic process where name=\"%s.exe\" | findstr \"%s.exe\"" % (processerName, processerName)) + else: + killCmd = ( + "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" + % processerName + ) + psCmd = ("ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % processerName) + processID = "" + + try: + processID = subprocess.check_output(psCmd, shell=True) + except Exception as err: + processID = "" + print('**** warn: ', err) + while processID: os.system(killCmd) time.sleep(1) - processID = subprocess.check_output(psCmd, shell=True) + try: + processID = subprocess.check_output(psCmd, shell=True) + except Exception as err: + processID = "" + print('**** warn: ', err) def close(self): self.cursor.close() diff --git a/tests/system-test/7-tmq/tmqDropConsumer.py b/tests/system-test/7-tmq/tmqDropConsumer.py index 06ce4c0fd7..0f8cffa595 100644 --- a/tests/system-test/7-tmq/tmqDropConsumer.py +++ b/tests/system-test/7-tmq/tmqDropConsumer.py @@ -176,7 +176,10 @@ class TDTestCase: # use taosBenchmark to subscribe binPath = self.getPath() - cmd = "nohup %s -f ./7-tmq/tmqDropConsumer.json > /dev/null 2>&1 & " % binPath + if platform.system().lower() == 'windows': + cmd = f"mintty -h never %s -f ./7-tmq/tmqDropConsumer.json > NUL 2>&1" % binPath + else: + cmd = f"nohup %s -f ./7-tmq/tmqDropConsumer.json > /dev/null 2>&1 & " % binPath tdLog.info("%s"%(cmd)) os.system(cmd)