未验证 提交 3d843d32 编写于 作者: S slguan 提交者: GitHub

Merge pull request #1686 from taosdata/make-python-test-dynamically-load-module

make python test framework dynamically load module
......@@ -17,6 +17,7 @@ from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn):
tdLog.debug("start to execute %s" % __file__)
......@@ -24,25 +25,24 @@ class TDTestCase:
def run(self):
tdSql.prepare()
tdSql.execute('show databases')
tdSql.execute('drop database if exists db')
tdSql.execute('create database db')
tdSql.execute('use db')
tdSql.execute('create table tb (ts timestamp, speed int)')
ret = tdSql.execute('create table tb (ts timestamp, speed int)')
insertRows = 10
tdLog.info("insert %d rows" % (insertRows))
for i in range(0, insertRows):
tdSql.execute('insert into tb values (now + %dm, %d)' % (i, i))
ret = tdSql.execute(
'insert into tb values (now + %dm, %d)' %
(i, i))
# tdLog.info("insert earlier data")
# tdSql.execute('insert into tb values (now - 5m , 10)')
# tdSql.execute('insert into tb values (now - 6m , 10)')
# tdSql.execute('insert into tb values (now - 7m , 10)')
# tdSql.execute('insert into tb values (now - 8m , 10)')
tdLog.info("insert earlier data")
tdSql.execute('insert into tb values (now - 5m , 10)')
tdSql.execute('insert into tb values (now - 6m , 10)')
tdSql.execute('insert into tb values (now - 7m , 10)')
tdSql.execute('insert into tb values (now - 8m , 10)')
tdSql.query("select * from tb")
tdSql.checkRows(insertRows)
tdSql.checkRows(insertRows + 4)
def stop(self):
tdSql.close()
......
#!/bin/bash
python2 ./test.py -f insert/basic.py $1
python2 ./test.py -s $1
python3 ./test.py -f insert/basic.py $1
python3 ./test.py -s $1
......@@ -24,8 +24,6 @@ from util.cases import *
import taos
# add testcase here:
from insert.basic import *
if __name__ == "__main__":
fileName = "all"
......@@ -35,7 +33,7 @@ if __name__ == "__main__":
valgrind = 0
stop = 0
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:scgh', [
'file=', 'path=', 'master', 'stop', 'cluster', 'valgrind', 'help'])
'file=', 'path=', 'master', 'stop', 'cluster', 'valgrind', 'help'])
for key, value in opts:
if key in ['-h', '--help']:
tdLog.printNoPrefix(
......@@ -72,13 +70,13 @@ if __name__ == "__main__":
toBeKilled = "valgrind.bin"
killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -HUP " % toBeKilled
os.system(killCmd)
time.sleep(1)
# os.system(killCmd)
# time.sleep(1)
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
processID = subprocess.check_output(psCmd, shell=True)
while( processID ):
while(processID):
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(psCmd, shell=True)
......@@ -87,6 +85,7 @@ if __name__ == "__main__":
if masterIp == "":
tdDnodes.init(deployPath)
tdDnodes.setTestCluster(testCluster)
tdDnodes.setValgrind(valgrind)
if testCluster:
......
......@@ -15,6 +15,8 @@ import sys
import os
import time
import datetime
import inspect
import importlib
from util.log import *
......@@ -30,6 +32,10 @@ class TDCases:
self.windowsCases = []
self.clusterCases = []
def __dynamicLoadModule(self, fileName):
moduleName = fileName.replace(".py", "").replace("/", ".")
return importlib.import_module(moduleName, package='..')
def addWindows(self, name, case):
self.windowsCases.append(TDCase(name, case))
......@@ -40,64 +46,93 @@ class TDCases:
self.clusterCases.append(TDCase(name, case))
def runAllLinux(self, conn):
tdLog.notice("run total %d cases" % (len(self.linuxCases)))
for case in self.linuxCases:
case.case.init(conn)
case.case.run()
case.case.stop()
tdLog.notice("total %d cases executed" % (len(self.linuxCases)))
# TODO: load all Linux cases here
runNum = 0
for tmp in self.linuxCases:
if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase()
case.init(conn)
case.run()
case.stop()
runNum += 1
continue
tdLog.notice("total %d Linux test case(s) executed" % (runNum))
def runOneLinux(self, conn, fileName):
tdLog.notice("run cases like %s" % (fileName))
testModule = self.__dynamicLoadModule(fileName)
runNum = 0
for case in self.linuxCases:
if case.name.find(fileName) != -1:
case.case.init(conn)
case.case.run()
case.case.stop()
time.sleep(5)
for tmp in self.linuxCases:
if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase()
case.init(conn)
case.run()
case.stop()
runNum += 1
tdLog.notice("total %d cases executed" % (runNum))
continue
tdLog.notice("total %d Linux test case(s) executed" % (runNum))
def runAllWindows(self, conn):
tdLog.notice("run total %d cases" % (len(self.windowsCases)))
for case in self.windowsCases:
case.case.init(conn)
case.case.run()
case.case.stop()
tdLog.notice("total %d cases executed" % (len(self.windowsCases)))
# TODO: load all Windows cases here
runNum = 0
for tmp in self.windowsCases:
if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase()
case.init(conn)
case.run()
case.stop()
runNum += 1
continue
tdLog.notice("total %d Windows test case(s) executed" % (runNum))
def runOneWindows(self, conn, fileName):
tdLog.notice("run cases like %s" % (fileName))
testModule = self.__dynamicLoadModule(fileName)
runNum = 0
for case in self.windowsCases:
if case.name.find(fileName) != -1:
case.case.init(conn)
case.case.run()
case.case.stop()
time.sleep(2)
for tmp in self.windowsCases:
if tmp.name.find(fileName) != -1:
case = testModule.TDTestCase()
case.init(conn)
case.run()
case.stop()
runNum += 1
tdLog.notice("total %d cases executed" % (runNum))
continue
tdLog.notice("total %d Windows case(s) executed" % (runNum))
def runAllCluster(self):
tdLog.notice("run total %d cases" % (len(self.clusterCases)))
for case in self.clusterCases:
case.case.init()
case.case.run()
case.case.stop()
tdLog.notice("total %d cases executed" % (len(self.clusterCases)))
# TODO: load all cluster case module here
runNum = 0
for tmp in self.clusterCases:
if tmp.name.find(fileName) != -1:
tdLog.notice("run cases like %s" % (fileName))
case = testModule.TDTestCase()
case.init()
case.run()
case.stop()
runNum += 1
continue
tdLog.notice("total %d Cluster test case(s) executed" % (runNum))
def runOneCluster(self, fileName):
tdLog.notice("run cases like %s" % (fileName))
testModule = self.__dynamicLoadModule(fileName)
runNum = 0
for case in self.clusterCases:
if case.name.find(fileName) != -1:
case.case.init()
case.case.run()
case.case.stop()
time.sleep(2)
for tmp in self.clusterCases:
if tmp.name.find(fileName) != -1:
tdLog.notice("run cases like %s" % (fileName))
case = testModule.TDTestCase()
case.init()
case.run()
case.stop()
runNum += 1
tdLog.notice("total %d cases executed" % (runNum))
continue
tdLog.notice("total %d Cluster test case(s) executed" % (runNum))
tdCases = TDCases()
......@@ -30,9 +30,6 @@ class TDSimClient:
if os.system(cmd) != 0:
tdLog.exit(cmd)
def setValgrind(self, value):
self.valgrind = value
def deploy(self):
self.logDir = "%s/sim/psim/log" % (self.path,)
self.cfgDir = "%s/sim/psim/cfg" % (self.path)
......@@ -82,11 +79,15 @@ class TDDnode:
self.index = index
self.running = 0
self.deployed = 0
self.testCluster = False
self.valgrind = 0
def init(self, path):
self.path = path
def setTestCluster(self, value):
self.testCluster = value
def setValgrind(self, value):
self.valgrind = value
......@@ -124,7 +125,9 @@ class TDDnode:
if os.system(cmd) != 0:
tdLog.exit(cmd)
self.startIP()
if self.testCluster:
self.startIP()
self.cfg("masterIp", "192.168.0.1")
self.cfg("secondIp", "192.168.0.2")
self.cfg("publicIp", "192.168.0.%d" % (self.index))
......@@ -292,11 +295,15 @@ class TDDnodes:
self.sim.init(self.path)
self.sim.deploy()
def setTestCluster(self, value):
self.testCluster = value
def setValgrind(self, value):
self.valgrind = value
def deploy(self, index):
self.check(index)
self.dnodes[index - 1].setTestCluster(self.testCluster)
self.dnodes[index - 1].setValgrind(self.valgrind)
self.dnodes[index - 1].deploy()
......@@ -318,11 +325,15 @@ class TDDnodes:
def startIP(self, index):
self.check(index)
self.dnodes[index - 1].startIP()
if self.testCluster:
self.dnodes[index - 1].startIP()
def stopIP(self, index):
self.check(index)
self.dnodes[index - 1].stopIP()
if self.dnodes[index - 1].testCluster:
self.dnodes[index - 1].stopIP()
def check(self, index):
if index < 1 or index > 10:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册