diff --git a/tests/pytest/insert/basic.py b/tests/pytest/insert/basic.py index 5ec83fd249d200cf2612b0688b97bb92cb14f75b..e8698e9d0502eb6ef3e335daefdd9bf9854c30da 100644 --- a/tests/pytest/insert/basic.py +++ b/tests/pytest/insert/basic.py @@ -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() diff --git a/tests/pytest/simpletest.sh b/tests/pytest/simpletest.sh index a6e023bde8c0a38a7d87b772639fed38233efb71..b77c1aa142413b74256b125f6c4a84485be66cff 100755 --- a/tests/pytest/simpletest.sh +++ b/tests/pytest/simpletest.sh @@ -1,3 +1,3 @@ #!/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 diff --git a/tests/pytest/test.py b/tests/pytest/test.py index f5d4cc7c2998f55bbfe5c9f94ad872357b4a4bab..55ec46e526c89fc1c6e99671a63670a167c58aa8 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -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: diff --git a/tests/pytest/util/cases.py b/tests/pytest/util/cases.py index 320c9d974f4253c2fe12951e208281d15b1010ed..4bd1b1e9d1a0d734852584450d02b4ff91124d0f 100644 --- a/tests/pytest/util/cases.py +++ b/tests/pytest/util/cases.py @@ -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() diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 45eaa9b30b75d92d87f9a4d6c04dcc7e0436266b..6a9c2607e63f1d145af387198e1ac1fb077135ca 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -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: