未验证 提交 2a661a2a 编写于 作者: H Hui Li 提交者: GitHub

Merge pull request #7861 from taosdata/test/python_case_windows

[TD-6591]test framework on windows
import hudson.model.Result import hudson.model.Result
import hudson.model.*;
import jenkins.model.CauseOfInterruption import jenkins.model.CauseOfInterruption
properties([pipelineTriggers([githubPush()])]) properties([pipelineTriggers([githubPush()])])
node { node {
...@@ -6,6 +7,7 @@ node { ...@@ -6,6 +7,7 @@ node {
} }
def skipbuild=0 def skipbuild=0
def win_stop=0
def abortPreviousBuilds() { def abortPreviousBuilds() {
def currentJobName = env.JOB_NAME def currentJobName = env.JOB_NAME
...@@ -110,7 +112,83 @@ def pre_test(){ ...@@ -110,7 +112,83 @@ def pre_test(){
''' '''
return 1 return 1
} }
def pre_test_win(){
bat '''
cd C:\\
rd /s /Q C:\\TDengine
cd C:\\workspace\\TDinternal
rd /s /Q C:\\workspace\\TDinternal\\debug
cd C:\\workspace\\TDinternal\\community
git reset --hard HEAD~10
'''
script {
if (env.CHANGE_TARGET == 'master') {
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout 2.0
'''
}
else{
bat '''
cd C:\\workspace\\TDinternal\\community
git checkout develop
'''
}
}
bat'''
cd C:\\workspace\\TDinternal\\community
git pull
git fetch origin +refs/pull/%CHANGE_ID%/merge
git checkout -qf FETCH_HEAD
git clean -dfx
cd C:\\workspace\\TDinternal
git reset --hard HEAD~10
'''
script {
if (env.CHANGE_TARGET == 'master') {
bat '''
cd C:\\workspace\\TDinternal
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
bat '''
cd C:\\workspace\\TDinternal
git checkout 2.0
'''
}
else{
bat '''
cd C:\\workspace\\TDinternal
git checkout develop
'''
}
}
bat '''
cd C:\\workspace\\TDinternal
git pull
date
git clean -dfx
mkdir debug
cd debug
call "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" amd64
cmake ../ -G "NMake Makefiles"
nmake
nmake install
xcopy /e/y/i/f C:\\workspace\\TDinternal\\debug\\build\\lib\\taos.dll C:\\Windows\\System32
cd C:\\workspace\\TDinternal\\community\\src\\connector\\python
python -m pip install .
'''
return 1
}
pipeline { pipeline {
agent none agent none
environment{ environment{
...@@ -387,7 +465,37 @@ pipeline { ...@@ -387,7 +465,37 @@ pipeline {
date''' date'''
} }
} }
} }
stage('build'){
agent{label " wintest "}
steps {
pre_test()
script{
while(win_stop == 0){
sleep(1)
}
}
}
}
stage('test'){
agent{label "win"}
steps{
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
pre_test_win()
bat'''
cd C:\\workspace\\TDinternal\\community\\tests\\pytest
.\\test-all.bat Wintest
'''
}
script{
win_stop=1
}
}
}
} }
} }
} }
......
python .\test.py -f insert\basic.py
python .\test.py -f insert\int.py
python .\test.py -f insert\float.py
python .\test.py -f insert\bigint.py
python .\test.py -f insert\bool.py
python .\test.py -f insert\double.py
python .\test.py -f insert\smallint.py
python .\test.py -f insert\tinyint.py
python .\test.py -f insert\date.py
python .\test.py -f insert\binary.py
python .\test.py -f insert\nchar.py
python .\test.py -f query\filter.py
python .\test.py -f query\filterCombo.py
python .\test.py -f query\queryNormal.py
python .\test.py -f query\queryError.py
python .\test.py -f query\filterAllIntTypes.py
python .\test.py -f query\filterFloatAndDouble.py
python .\test.py -f query\filterOtherTypes.py
python .\test.py -f query\querySort.py
python .\test.py -f query\queryJoin.py
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform
import sys import sys
from util.log import * from util.log import *
from util.cases import * from util.cases import *
...@@ -53,9 +54,10 @@ class TDTestCase: ...@@ -53,9 +54,10 @@ class TDTestCase:
tdLog.info("tdSql.checkData(0, 0, '34567')") tdLog.info("tdSql.checkData(0, 0, '34567')")
tdSql.checkData(0, 0, '34567') tdSql.checkData(0, 0, '34567')
tdLog.info("insert into tb values (now+4a, \"'';\")") tdLog.info("insert into tb values (now+4a, \"'';\")")
config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '') if platform.system() == "Linux":
result = ''.join(os.popen(r"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines()) config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '')
if "Query OK" not in result: tdLog.exit("err:insert '';") result = ''.join(os.popen(r"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines())
if "Query OK" not in result: tdLog.exit("err:insert '';")
tdLog.info('drop database db') tdLog.info('drop database db')
tdSql.execute('drop database db') tdSql.execute('drop database db')
tdLog.info('show databases') tdLog.info('show databases')
......
...@@ -15,6 +15,7 @@ import sys ...@@ -15,6 +15,7 @@ import sys
from util.log import * from util.log import *
from util.cases import * from util.cases import *
from util.sql import * from util.sql import *
import platform
class TDTestCase: class TDTestCase:
...@@ -37,7 +38,7 @@ class TDTestCase: ...@@ -37,7 +38,7 @@ class TDTestCase:
tdSql.error("insert into tb values (now, 'taosdata001')") tdSql.error("insert into tb values (now, 'taosdata001')")
tdSql.error("insert into tb(now, 😀)") if platform.system() == "Linux" : tdSql.error("insert into tb(now, 😀)")
tdSql.query("select * from tb") tdSql.query("select * from tb")
tdSql.checkRows(2) tdSql.checkRows(2)
......
...@@ -17,6 +17,7 @@ from util.log import * ...@@ -17,6 +17,7 @@ from util.log import *
from util.cases import * from util.cases import *
from util.sql import * from util.sql import *
from util.dnodes import * from util.dnodes import *
import platform
class TDTestCase: class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
...@@ -137,8 +138,9 @@ class TDTestCase: ...@@ -137,8 +138,9 @@ class TDTestCase:
tdSql.checkData(1, 1, 421) tdSql.checkData(1, 1, 421)
tdSql.checkData(1, 2, "tm1") tdSql.checkData(1, 2, "tm1")
tdDnodes.stop(1) if platform.system() == "Linux":
tdDnodes.start(1) tdDnodes.stop(1)
tdDnodes.start(1)
tdSql.query("select last(*) from m1 group by tbname") tdSql.query("select last(*) from m1 group by tbname")
tdSql.checkData(0, 0, "2020-03-01 01:01:01") tdSql.checkData(0, 0, "2020-03-01 01:01:01")
......
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "DEL=%%a")
for /F "usebackq tokens=*" %%i in (fulltest.bat) do (
echo Processing %%i
call %%i ARG1 -w 1 -m %1 > result.txt 2>error.txt
if errorlevel 1 ( call :colorEcho 0c "failed" &echo. && exit 8 ) else ( call :colorEcho 0a "Success" &echo. )
)
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
\ No newline at end of file
...@@ -18,6 +18,7 @@ import getopt ...@@ -18,6 +18,7 @@ import getopt
import subprocess import subprocess
import time import time
from distutils.log import warn as printf from distutils.log import warn as printf
from fabric2 import Connection
from util.log import * from util.log import *
from util.dnodes import * from util.dnodes import *
...@@ -35,8 +36,9 @@ if __name__ == "__main__": ...@@ -35,8 +36,9 @@ if __name__ == "__main__":
logSql = True logSql = True
stop = 0 stop = 0
restart = False restart = False
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghr', [ windows = 0
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help']) opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrw', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'windows'])
for key, value in opts: for key, value in opts:
if key in ['-h', '--help']: if key in ['-h', '--help']:
tdLog.printNoPrefix( tdLog.printNoPrefix(
...@@ -49,6 +51,7 @@ if __name__ == "__main__": ...@@ -49,6 +51,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-c Test Cluster Flag') tdLog.printNoPrefix('-c Test Cluster Flag')
tdLog.printNoPrefix('-g valgrind Test Flag') tdLog.printNoPrefix('-g valgrind Test Flag')
tdLog.printNoPrefix('-r taosd restart test') tdLog.printNoPrefix('-r taosd restart test')
tdLog.printNoPrefix('-w taos on windows')
sys.exit(0) sys.exit(0)
if key in ['-r', '--restart']: if key in ['-r', '--restart']:
...@@ -81,6 +84,9 @@ if __name__ == "__main__": ...@@ -81,6 +84,9 @@ if __name__ == "__main__":
if key in ['-s', '--stop']: if key in ['-s', '--stop']:
stop = 1 stop = 1
if key in ['-w', '--windows']:
windows = 1
if (stop != 0): if (stop != 0):
if (valgrind == 0): if (valgrind == 0):
toBeKilled = "taosd" toBeKilled = "taosd"
...@@ -111,66 +117,81 @@ if __name__ == "__main__": ...@@ -111,66 +117,81 @@ if __name__ == "__main__":
tdLog.info('stop All dnodes') tdLog.info('stop All dnodes')
tdDnodes.init(deployPath)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
is_test_framework = 0
key_word = 'tdCases.addLinux'
try:
if key_word in open(fileName).read():
is_test_framework = 1
except:
pass
if is_test_framework:
moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName)
try:
ucase = uModule.TDTestCase()
tdDnodes.deploy(1,ucase.updatecfgDict)
except :
tdDnodes.deploy(1,{})
else:
tdDnodes.deploy(1,{})
tdDnodes.start(1)
if masterIp == "": if masterIp == "":
host = '127.0.0.1' host = '127.0.0.1'
else: else:
host = masterIp host = masterIp
tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("Procedures for tdengine deployed in %s" % (host))
if windows:
tdCases.logSql(logSql) tdCases.logSql(logSql)
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
else:
tdLog.info("Procedures for testing self-deployment") tdLog.info("Procedures for testing self-deployment")
td_clinet = TDSimClient("C:\\TDengine")
td_clinet.deploy()
remote_conn = Connection("root@%s"%host)
with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'):
remote_conn.run("python3 ./test.py")
conn = taos.connect( conn = taos.connect(
host, host="%s"%(host),
config=tdDnodes.getSimCfgPath()) config=td_clinet.cfgDir)
if fileName == "all": tdCases.runOneWindows(conn, fileName)
tdCases.runAllLinux(conn) else:
tdDnodes.init(deployPath)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
tdDnodes.stopAll()
is_test_framework = 0
key_word = 'tdCases.addLinux'
try:
if key_word in open(fileName).read():
is_test_framework = 1
except:
pass
if is_test_framework:
moduleName = fileName.replace(".py", "").replace("/", ".")
uModule = importlib.import_module(moduleName)
try:
ucase = uModule.TDTestCase()
tdDnodes.deploy(1,ucase.updatecfgDict)
except :
tdDnodes.deploy(1,{})
else:
pass
tdDnodes.deploy(1,{})
tdDnodes.start(1)
tdCases.logSql(logSql)
if testCluster:
tdLog.info("Procedures for testing cluster")
if fileName == "all":
tdCases.runAllCluster()
else:
tdCases.runOneCluster(fileName)
else: else:
tdCases.runOneLinux(conn, fileName) tdLog.info("Procedures for testing self-deployment")
if restart: conn = taos.connect(
if fileName == "all": host,
tdLog.info("not need to query ") config=tdDnodes.getSimCfgPath())
else: if fileName == "all":
sp = fileName.rsplit(".", 1) tdCases.runAllLinux(conn)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
time.sleep(1)
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py")
else: else:
tdLog.info("not need to query") tdCases.runOneWindows(conn, fileName)
if restart:
if fileName == "all":
tdLog.info("not need to query ")
else:
sp = fileName.rsplit(".", 1)
if len(sp) == 2 and sp[1] == "py":
tdDnodes.stopAll()
tdDnodes.start(1)
time.sleep(1)
conn = taos.connect( host, config=tdDnodes.getSimCfgPath())
tdLog.info("Procedures for tdengine deployed in %s" % (host))
tdLog.info("query test after taosd restart")
tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py")
else:
tdLog.info("not need to query")
conn.close() conn.close()
...@@ -27,7 +27,7 @@ class TDTestCase: ...@@ -27,7 +27,7 @@ class TDTestCase:
def restart_taosd(self,db): def restart_taosd(self,db):
tdDnodes.stop(1) tdDnodes.stop(1)
tdDnodes.startWithoutSleep(1) tdDnodes.start(1)
tdSql.execute("use %s;" % db) tdSql.execute("use %s;" % db)
def date_to_timestamp_microseconds(self, date): def date_to_timestamp_microseconds(self, date):
......
...@@ -34,7 +34,7 @@ class TDCases: ...@@ -34,7 +34,7 @@ class TDCases:
self.clusterCases = [] self.clusterCases = []
def __dynamicLoadModule(self, fileName): def __dynamicLoadModule(self, fileName):
moduleName = fileName.replace(".py", "").replace("/", ".") moduleName = fileName.replace(".py", "").replace(os.sep, ".")
return importlib.import_module(moduleName, package='..') return importlib.import_module(moduleName, package='..')
def logSql(self, logSql): def logSql(self, logSql):
...@@ -80,7 +80,7 @@ class TDCases: ...@@ -80,7 +80,7 @@ class TDCases:
runNum += 1 runNum += 1
continue continue
def runAllWindows(self, conn): def runAllWindows(self, conn, fileName):
# TODO: load all Windows cases here # TODO: load all Windows cases here
runNum = 0 runNum = 0
for tmp in self.windowsCases: for tmp in self.windowsCases:
...@@ -101,12 +101,17 @@ class TDCases: ...@@ -101,12 +101,17 @@ class TDCases:
for tmp in self.windowsCases: for tmp in self.windowsCases:
if tmp.name.find(fileName) != -1: if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase() case = testModule.TDTestCase()
case.init(conn) case.init(conn, self._logSql)
case.run() try:
case.run()
except Exception as e:
tdLog.notice(repr(e))
tdLog.exit("%s failed" % (fileName))
case.stop() case.stop()
runNum += 1 runNum += 1
continue continue
tdLog.notice("total %d Windows case(s) executed" % (runNum)) tdLog.notice("total %d Windows case(s) executed" % (runNum))
def runAllCluster(self): def runAllCluster(self):
# TODO: load all cluster case module here # TODO: load all cluster case module here
......
...@@ -15,6 +15,8 @@ import sys ...@@ -15,6 +15,8 @@ import sys
import os import os
import os.path import os.path
import platform import platform
import pathlib
import shutil
import subprocess import subprocess
from time import sleep from time import sleep
from util.log import * from util.log import *
...@@ -62,32 +64,45 @@ class TDSimClient: ...@@ -62,32 +64,45 @@ class TDSimClient:
cmd = "echo %s %s >> %s" % (option, value, self.cfgPath) cmd = "echo %s %s >> %s" % (option, value, self.cfgPath)
if os.system(cmd) != 0: if os.system(cmd) != 0:
tdLog.exit(cmd) tdLog.exit(cmd)
def os_string(self,path):
os_path = path.replace("/",os.sep)
return os_path
def deploy(self): def deploy(self):
self.logDir = "%s/sim/psim/log" % (self.path) self.logDir = self.os_string("%s/sim/psim/log" % (self.path))
self.cfgDir = "%s/sim/psim/cfg" % (self.path) self.cfgDir = self.os_string("%s/sim/psim/cfg" % (self.path))
self.cfgPath = "%s/sim/psim/cfg/taos.cfg" % (self.path) self.cfgPath = self.os_string("%s/sim/psim/cfg/taos.cfg" % (self.path))
cmd = "rm -rf " + self.logDir # cmd = "rm -rf " + self.logDir
if os.system(cmd) != 0: # if os.system(cmd) != 0:
tdLog.exit(cmd) # tdLog.exit(cmd)
if os.path.exists(self.logDir):
cmd = "mkdir -p " + self.logDir try:
if os.system(cmd) != 0: shutil.rmtree(self.logDir)
tdLog.exit(cmd) except:
tdLog.exit("del %s failed"%self.logDir)
cmd = "rm -rf " + self.cfgDir # cmd = "mkdir -p " + self.logDir
if os.system(cmd) != 0: # if os.system(cmd) != 0:
tdLog.exit(cmd) # tdLog.exit(cmd)
os.makedirs(self.logDir)
cmd = "mkdir -p " + self.cfgDir # cmd = "rm -rf " + self.cfgDir
if os.system(cmd) != 0: # if os.system(cmd) != 0:
tdLog.exit(cmd) # tdLog.exit(cmd)
if os.path.exists(self.cfgDir):
cmd = "touch " + self.cfgPath try:
if os.system(cmd) != 0: shutil.rmtree(self.cfgDir)
tdLog.exit(cmd) except:
tdLog.exit("del %s failed"%self.cfgDir)
# cmd = "mkdir -p " + self.cfgDir
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
os.makedirs(self.cfgDir)
# cmd = "touch " + self.cfgPath
# if os.system(cmd) != 0:
# tdLog.exit(cmd)
try:
pathlib.Path(self.cfgPath).touch()
except:
tdLog.exit("create %s failed"%self.cfgPath)
if self.testCluster: if self.testCluster:
self.cfg("masterIp", "192.168.0.1") self.cfg("masterIp", "192.168.0.1")
self.cfg("secondIp", "192.168.0.2") self.cfg("secondIp", "192.168.0.2")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册