From c7e4680e3ae42a535f5f314ecbda721cbef6d8e8 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sat, 22 Feb 2025 22:03:48 +0800 Subject: [PATCH] fix: -R -h can coredump and memory leak --- tests/army/cmdline/taosCli.py | 72 +++++++++++++++++++++-------------- tools/shell/src/shellUtil.c | 30 ++++++++------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/tests/army/cmdline/taosCli.py b/tests/army/cmdline/taosCli.py index 4619fe72fa..897bb4e695 100644 --- a/tests/army/cmdline/taosCli.py +++ b/tests/army/cmdline/taosCli.py @@ -78,33 +78,12 @@ class TDTestCase(TBase): # last line self.checkSame(rlist[idx][:len(result)], result) - def checkDumpInOutMode(self, source, arg): - mode = arg[0] - self.taos(f'{mode} -s "source {source}" ') + # -B have some problem need todo + self.taos(f'{mode} -B -s "select * from {db}.{stb} where ts < 1"') - def checkDumpInOut(self): - args = [ - ["", 18, 346, -2, 310], - ["-R -r", 22, 350, -3, 313], - ["-T 40 -E http://localhost:6041", 21, 349, -3, 312] - ] - - source = "cmdline/data/source.sql" - - for arg in args: - self.checkDumpInOutMode(source, arg) - - db = "db" - insertRows = 5 - self.taos(f'-s "select * from {db}.d0 >>d0.csv" ') - self.taos(f'-s "delete from {db}.d0" ') - self.taos(f'-s "insert into {db}.d0 file d0.csv" ') - sql = f"select count(*) from {db}.d0" - tdSql.checkAgg(sql, insertRows) - sql = f"select first(voltage) from {db}.d0" - tdSql.checkFirstValue(sql, 1) - sql = f"select last(voltage) from {db}.d0" - tdSql.checkFirstValue(sql, 5) + # get empty result + rlist = self.taos(f'{mode} -s "select * from {db}.{stb} where ts < 1"') + self.checkListString(rlist, "Query OK, 0 row(s) in set") def checkBasic(self): tdLog.info(f"check describe show full.") @@ -123,6 +102,45 @@ class TDTestCase(TBase): self.checkResultWithMode(db, stb, arg) + def checkDumpInOutMode(self, source, arg, db, insertRows): + mode = arg[0] + self.taos(f'{mode} -s "source {source}" ') + self.taos(f'{mode} -s "select * from {db}.d0; >>d0.csv" ') + + # use db + rlist = self.taos(f'{mode} -s "use {db};" ') + self.checkListString(rlist, "Database changed") + # update sql + rlist = self.taos(f'{mode} -s "alter local \'resetlog\';" ') + self.checkListString(rlist, "Query O") + + # only native support csv import + if mode == "": + self.taos(f'{mode} -s "delete from {db}.d0" ') + self.taos(f'{mode} -s "insert into {db}.d0 file d0.csv" ') + + sql = f"select count(*) from {db}.d0" + self.taos(f'{mode} -B -s "{sql}" ') + tdSql.checkAgg(sql, insertRows) + sql = f"select first(voltage) from {db}.d0" + tdSql.checkFirstValue(sql, 1) + sql = f"select last(voltage) from {db}.d0" + tdSql.checkFirstValue(sql, 5) + + def checkDumpInOut(self): + args = [ + ["", 18], + ["-R ", 22], + ["-E http://localhost:6041", 21] + ] + + source = "cmdline/data/source.sql" + db = "db" + insertRows = 5 + for arg in args: + # insert + self.checkDumpInOutMode(source, arg, db, insertRows) + def checkVersion(self): rlist1 = self.taos("-V") rlist2 = self.taos("--version") @@ -187,8 +205,6 @@ class TDTestCase(TBase): ] for arg in args: - print(arg[0]) - print(arg[1]) rlist = self.taos(arg[0]) if arg[1] != None: self.checkListString(rlist, arg[1]) diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index 0350d934a7..a8c1193ab8 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -122,6 +122,7 @@ void shellCheckServerStatus() { } while (1); } #ifdef WEBSOCKET +char dsn[1024] = "ws://localhost:6041"; void shellCheckConnectMode() { if (shell.args.dsn) { shell.args.cloud = true; @@ -144,21 +145,22 @@ void shellCheckConnectMode() { shell.args.restful = false; return; } - - if (shell.args.restful) { - if (!shell.args.host) { - shell.args.host = "localhost"; - } - if (!shell.args.port) { - shell.args.port = 6041; - } - shell.args.dsn = taosMemoryCalloc(1, 1024); - snprintf(shell.args.dsn, 1024, "ws://%s:%d", - shell.args.host, shell.args.port); - } - shell.args.cloud = false; - return; } + + if (shell.args.restful) { + if (!shell.args.host) { + shell.args.host = "localhost"; + } + if (!shell.args.port) { + shell.args.port = 6041; + } + shell.args.dsn = dsn; + snprintf(shell.args.dsn, 1024, "ws://%s:%d", + shell.args.host, shell.args.port); + } + shell.args.cloud = false; + return; + } #endif