diff --git a/Jenkinsfile2 b/Jenkinsfile2 index f44339c8c1..63ebf3a6ed 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -6,6 +6,7 @@ node { file_zh_changed = '' file_en_changed = '' file_no_doc_changed = '1' +file_only_tdgpt_change_except = '1' def abortPreviousBuilds() { def currentJobName = env.JOB_NAME def currentBuildNumber = env.BUILD_NUMBER.toInteger() @@ -73,9 +74,19 @@ def check_docs(){ ''', returnStdout: true ).trim() + + file_only_tdgpt_change_except = sh ( + script: ''' + cd ${WKC} + git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep -v "^docs/en/"|grep -v "^docs/zh/"|grep -v ".md$" | grep -v "forecastoperator.c\\|anomalywindowoperator.c" |grep -v "tsim/analytics" |grep -v "tdgpt_cases.task" || : + ''', + returnStdout: true + ).trim() + echo "file_zh_changed: ${file_zh_changed}" echo "file_en_changed: ${file_en_changed}" echo "file_no_doc_changed: ${file_no_doc_changed}" + echo "file_only_tdgpt_change_except: ${file_only_tdgpt_change_except}" } } @@ -385,7 +396,7 @@ def run_win_test() { } pipeline { - agent none + agent any options { skipDefaultCheckout() } environment{ WKDIR = '/var/lib/jenkins/workspace' @@ -462,19 +473,27 @@ pipeline { WIN_COMMUNITY_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community" WIN_SYSTEM_TEST_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community\\tests\\system-test" } + when { + beforeAgent true + expression { file_only_tdgpt_change_except != '' } + } steps { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { timeout(time: 126, unit: 'MINUTES'){ - pre_test_win() - pre_test_build_win() - run_win_ctest() - run_win_test() + pre_test_win() + pre_test_build_win() + run_win_ctest() + run_win_test() } } } } stage('mac test') { agent{label " Mac_catalina "} + when { + beforeAgent true + expression { file_only_tdgpt_change_except != '' } + } steps { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { timeout(time: 60, unit: 'MINUTES'){ @@ -550,28 +569,25 @@ pipeline { cd ${WKC}/tests/parallel_test ./run_scan_container.sh -d ${WKDIR} -b ${BRANCH_NAME}_${BUILD_ID} -f ${WKDIR}/tmp/${BRANCH_NAME}_${BUILD_ID}/docs_changed.txt ''' + extra_param + ''' ''' - sh ''' - cd ${WKC}/tests/parallel_test - export DEFAULT_RETRY_TIME=2 - date - ''' + timeout_cmd + ''' time ./run.sh -e -m /home/m.json -t cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 1200 ''' + extra_param + ''' - ''' + if ( file_no_doc_changed =~ /forecastoperator.c|anomalywindowoperator.c|tsim\/analytics|tdgpt_cases.task/ ) { + sh ''' + cd ${WKC}/tests/parallel_test + export DEFAULT_RETRY_TIME=2 + date + timeout 600 time ./run.sh -e -m /home/m.json -t tdgpt_cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 300 ''' + extra_param + ''' + ''' + } + if ( file_only_tdgpt_change_except != '' ) { + sh ''' + cd ${WKC}/tests/parallel_test + export DEFAULT_RETRY_TIME=2 + date + ''' + timeout_cmd + ''' time ./run.sh -e -m /home/m.json -t cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 1200 ''' + extra_param + ''' + ''' + } } } } - /*catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { - timeout(time: 15, unit: 'MINUTES'){ - script { - sh ''' - echo "packaging ..." - date - rm -rf ${WKC}/release/* - cd ${WKC}/packaging - ./release.sh -v cluster -n 3.0.0.100 -s static - ''' - } - } - }*/ } } } diff --git a/packaging/smokeTest/test_anode.py b/packaging/smokeTest/test_anode.py new file mode 100644 index 0000000000..a97a2c6650 --- /dev/null +++ b/packaging/smokeTest/test_anode.py @@ -0,0 +1,134 @@ +import pytest +import subprocess +import os +from versionCheckAndUninstallforPytest import UninstallTaos +import platform +import re +import time +import signal +import logging + + + +system = platform.system() +current_path = os.path.abspath(os.path.dirname(__file__)) + +with open("%s/test_server_unix_tdgpt" % current_path) as f: + cases = f.read().splitlines() + +OEM = ["ProDB"] + + +@pytest.fixture(scope="module") +def get_config(request): + verMode = request.config.getoption("--verMode") + taosVersion = request.config.getoption("--tVersion") + baseVersion = request.config.getoption("--baseVersion") + sourcePath = request.config.getoption("--sourcePath") + config = { + "verMode": verMode, + "taosVersion": taosVersion, + "baseVersion": baseVersion, + "sourcePath": sourcePath, + "system": platform.system(), + "arch": platform.machine() + } + return config + + +@pytest.fixture(scope="module") +def setup_module(get_config): + def run_cmd(command): + print("CMD:", command) + result = subprocess.run(command, capture_output=True, text=True, shell=True) + print("STDOUT:", result.stdout) + print("STDERR:", result.stderr) + print("Return Code:", result.returncode) + assert result.returncode == 0 + return result + + # setup before module tests + config = get_config + if config["system"] == "Windows": + cmd = r"mkdir ..\..\debug\build\bin" + else: + cmd = "mkdir -p ../../debug/build/bin/" + subprocess.getoutput(cmd) + if config["system"] == "Linux" or config["system"] == "Darwin" : # add tmq_sim + cmd = "cp -rf ../../../debug/build/bin/tmq_sim ../../debug/build/bin/." + subprocess.getoutput(cmd) + if config["system"] == "Darwin": + cmd = "sudo cp -rf /usr/local/bin/taos* ../../debug/build/bin/" + elif config["system"] == "Windows": + cmd = r"xcopy C:\TDengine\taos*.exe ..\..\debug\build\bin /Y" + else: + if config["baseVersion"] in OEM: + cmd = '''sudo find /usr/bin -name 'prodb*' -exec sh -c 'for file; do cp "$file" "../../debug/build/bin/taos${file##/usr/bin/%s}"; done' sh {} +''' % ( + config["baseVersion"].lower()) + else: + cmd = "sudo cp /usr/bin/taos* ../../debug/build/bin/" + run_cmd(cmd) + if config["baseVersion"] in OEM: # mock OEM + cmd = "sed -i 's/taos.cfg/%s.cfg/g' ../../tests/pytest/util/dnodes.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taosdlog.0/%sdlog.0/g' ../../tests/pytest/util/dnodes.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taos.cfg/%s.cfg/g' ../../tests/army/frame/server/dnode.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taosdlog.0/%sdlog.0/g' ../../tests/army/frame/server/dnode.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "ln -s /usr/bin/prodb /usr/local/bin/taos" + subprocess.getoutput(cmd) + + # yield + # + # name = "taos" + # if config["baseVersion"] in OEM: + # name = config["baseVersion"].lower() + # subprocess.getoutput("rm /usr/local/bin/taos") + # subprocess.getoutput("pkill taosd") + # UninstallTaos(config["taosVersion"], config["verMode"], True, name) + + +# use pytest fixture to exec case +@pytest.fixture(params=cases) +def run_command(request): + commands = request.param + if commands.strip().startswith("#"): + pytest.skip("This case has been marked as skipped") + d, command = commands.strip().split(",") + if system == "Windows": + cmd = r"cd %s\..\..\tests\%s && %s" % (current_path, d, command) + else: + cmd = "cd %s/../../tests/%s&&sudo %s" % (current_path, d, command) + print(cmd) + result = subprocess.run(cmd, capture_output=True, text=True, shell=True) + return { + "command": command, + "stdout": result.stdout, + "stderr": result.stderr, + "returncode": result.returncode + } + + +class TestServer: + + @pytest.mark.all + def test_execute_cases(self, setup_module, run_command): + # assert the result + if run_command['returncode'] != 0: + print(f"Running command: {run_command['command']}") + print("STDOUT:", run_command['stdout']) + print("STDERR:", run_command['stderr']) + print("Return Code:", run_command['returncode']) + else: + print(f"Running command: {run_command['command']}") + if len(run_command['stdout']) > 1000: + print("STDOUT:", run_command['stdout'][:1000] + "...") + else: + print("STDOUT:", run_command['stdout']) + print("STDERR:", run_command['stderr']) + print("Return Code:", run_command['returncode']) + + assert run_command[ + 'returncode'] == 0, f"Command '{run_command['command']}' failed with return code {run_command['returncode']}" diff --git a/packaging/smokeTest/test_server_unix_tdgpt b/packaging/smokeTest/test_server_unix_tdgpt new file mode 100644 index 0000000000..6d099d6d02 --- /dev/null +++ b/packaging/smokeTest/test_server_unix_tdgpt @@ -0,0 +1 @@ +system-test,python3 ./test.py -f 9-tdgpt/test_gpt.py \ No newline at end of file diff --git a/source/libs/executor/src/forecastoperator.c b/source/libs/executor/src/forecastoperator.c index bf1efc54ca..a56b0dd214 100644 --- a/source/libs/executor/src/forecastoperator.c +++ b/source/libs/executor/src/forecastoperator.c @@ -169,6 +169,7 @@ static int32_t forecastCloseBuf(SForecastSupp* pSupp) { code = taosAnalBufWriteOptInt(pBuf, "start", start); if (code != 0) return code; + bool hasEvery = taosAnalGetOptInt(pSupp->algoOpt, "every", &every); if (!hasEvery) { qDebug("forecast every not found from %s, use %" PRId64, pSupp->algoOpt, every); diff --git a/tests/parallel_test/tdgpt_cases.task b/tests/parallel_test/tdgpt_cases.task new file mode 100644 index 0000000000..69123f4aac --- /dev/null +++ b/tests/parallel_test/tdgpt_cases.task @@ -0,0 +1,8 @@ +#Column Define +#caseID,rerunTimes,Run with Sanitizer,casePath,caseCommand +#NA,NA,y or n,script,./test.sh -f tsim/analytics/basic0.sim + +#tdgpt-test +,,n,script,./test.sh -f tsim/analytics/basic0.sim +#,,n,system-test,python3 ./test.py -f 9-tdgpt/test_gpt.py + diff --git a/tests/script/tsim/analytics/basic0.sim b/tests/script/tsim/analytics/basic0.sim index a4fe6354ae..77c9184e8f 100644 --- a/tests/script/tsim/analytics/basic0.sim +++ b/tests/script/tsim/analytics/basic0.sim @@ -4,7 +4,7 @@ system sh/exec.sh -n dnode1 -s start sql connect print =============== create anode -sql create anode '127.0.0.1:6090' +sql create anode '192.168.1.116:6050' sql show anodes if $rows != 1 then diff --git a/tests/system-test/9-tdgpt/test_gpt.py b/tests/system-test/9-tdgpt/test_gpt.py new file mode 100644 index 0000000000..16ab6bb22f --- /dev/null +++ b/tests/system-test/9-tdgpt/test_gpt.py @@ -0,0 +1,67 @@ +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +import taos + + + +class TDTestCase: + clientCfgDict = {'debugFlag': 135} + updatecfgDict = { + "debugFlag" : "135", + "queryBufferSize" : 10240, + 'clientCfg' : clientCfgDict + } + + def init(self, conn, logSql, replicaVal=1): + self.replicaVar = int(replicaVal) + tdLog.debug(f"start to excute {__file__}") + self.conn = conn + tdSql.init(conn.cursor(), False) + self.passwd = {'root':'taosdata', + 'test':'test'} + + def prepare_anode_data(self): + tdSql.execute(f"create anode '127.0.0.1:6090'") + tdSql.execute(f"create database db_gpt") + tdSql.execute(f"create table if not exists db_gpt.stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned);") + tdSql.execute(f"create table db_gpt.ct1 using db_gpt.stb tags(1000);") + tdSql.execute(f"insert into db_gpt.ct1(ts, c1) values(now-1a, 5)(now+1a, 14)(now+2a, 15)(now+3a, 15)(now+4a, 14);") + tdSql.execute(f"insert into db_gpt.ct1(ts, c1) values(now+5a, 19)(now+6a, 17)(now+7a, 16)(now+8a, 20)(now+9a, 22);") + tdSql.execute(f"insert into db_gpt.ct1(ts, c1) values(now+10a, 8)(now+11a, 21)(now+12a, 28)(now+13a, 11)(now+14a, 9);") + tdSql.execute(f"insert into db_gpt.ct1(ts, c1) values(now+15a, 29)(now+16a, 40);") + + + def test_forecast(self): + """ + Test forecast + """ + tdLog.info(f"Test forecast") + tdSql.query(f"SELECT _frowts, FORECAST(c1, \"algo=arima,alpha=95,period=10,start_p=1,max_p=5,start_q=1,max_q=5,d=1\") from db_gpt.ct1 ;") + tdSql.checkRows(10) + + def test_anomaly_window(self): + """ + Test anomaly window + """ + tdLog.info(f"Test anomaly window") + tdSql.query(f"SELECT _wstart, _wend, SUM(c1) FROM db_gpt.ct1 ANOMALY_WINDOW(c1, \"algo=iqr\");") + tdSql.checkData(0,2,40) + + + def run(self): + self.prepare_anode_data() + self.test_forecast() + self.test_anomaly_window() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + + + +