From 7769797dc97873714c1423c6abffff9fe1c75e4a Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Fri, 17 Jun 2022 16:28:07 +0800 Subject: [PATCH] fix: fixed connection error if -h was used (#13926) (#13937) * test: add test case for TS-1613 * fix: fixed connection error if -h was used * fix: assign port if -P is specified * fix: windows read env Co-authored-by: Ping Xiao Co-authored-by: xywang Co-authored-by: Yang Zhao Co-authored-by: XingY Wang Co-authored-by: Ping Xiao Co-authored-by: xywang --- src/kit/shell/src/shellLinux.c | 19 +++++++++---------- src/kit/shell/src/shellWindows.c | 6 ++++++ tests/pytest/client/client.py | 9 +++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index aa67019628..863da2e1a7 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -24,7 +24,6 @@ #define OPT_ABORT 1 /* �Cabort */ int indicator = 1; -int p_port = 6041; struct termios oldtio; extern int wcwidth(wchar_t c); @@ -79,7 +78,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { if (arg) { args.cloud = false; tsDnodeShellPort = atoi(arg); - p_port = atoi(arg); + args.port = atoi(arg); } else { fprintf(stderr, "Invalid port\n"); return -1; @@ -239,16 +238,16 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { argp_parse(&argp, argc, argv, 0, 0, arguments); if (args.cloudDsn == NULL) { - if (args.cloud) { - args.cloudDsn = getenv("TDENGINE_CLOUD_DSN"); - if (args.cloudDsn == NULL) { - args.cloud = false; - } - } + if (args.cloud) { + args.cloudDsn = getenv("TDENGINE_CLOUD_DSN"); + if (args.cloudDsn == NULL) { + args.cloud = false; + } + } } else { - args.cloud = true; + args.cloud = true; } - + if (arguments->abort) { #ifndef _ALPINE error(10, 0, "ABORTED"); diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index 608ec97408..83d8630eb8 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -250,6 +250,12 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { if (args.cloudDsn == NULL) { if (args.cloud) { args.cloudDsn = getenv("TDENGINE_CLOUD_DSN"); + if (args.cloudDsn[strlen(args.cloudDsn) - 1] == '\"') { + args.cloudDsn[strlen(args.cloudDsn) - 1] = '\0'; + } + if (args.cloudDsn[0] == '\"') { + args.cloudDsn += 1; + } if (args.cloudDsn == NULL) { args.cloud = false; } diff --git a/tests/pytest/client/client.py b/tests/pytest/client/client.py index 9a155a4df9..9192f7e6d3 100644 --- a/tests/pytest/client/client.py +++ b/tests/pytest/client/client.py @@ -15,6 +15,7 @@ import sys from util.log import * from util.cases import * from util.sql import * +import os from datetime import timedelta @@ -73,6 +74,14 @@ class TDTestCase: tdSql.checkRows(1) tdSql.checkData(0, 0, 2) tdSql.checkData(0, 1, "master") + + cmd = "taos -h 127.0.0.1 -s 'show databases'" + r = os.popen(cmd) + text = r.read() + r.close + + if 'Unable to establish connection' in text: + tdLog.exit("%s failed: command 'taos -h 127.0.0.1' Unable to establish connection" % __file__) def stop(self): tdSql.close() -- GitLab