diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index c23f0614c43ddb5548a305f6761888e9b56b244c..6c876dd9e58c3b7ff23e8094559eaf572ff22fd1 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -371,6 +371,7 @@ python3 ./test.py -f functions/function_irate.py python3 ./test.py -f functions/function_ceil.py python3 ./test.py -f functions/function_floor.py python3 ./test.py -f functions/function_round.py +python3 ./test.py -f functions/function_elapsed.py -r 1 python3 ./test.py -f insert/unsignedInt.py python3 ./test.py -f insert/unsignedBigint.py diff --git a/tests/pytest/functions/function_elapsed.py b/tests/pytest/functions/function_elapsed.py new file mode 100644 index 0000000000000000000000000000000000000000..f4f748620350576e49fdae75ccd8a1804ad9ecb1 --- /dev/null +++ b/tests/pytest/functions/function_elapsed.py @@ -0,0 +1,88 @@ +################################################################### +# Copyright (c) 2020 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +from util.cases import * +from util.sql import * +from functions.function_elapsed_case import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def genTime(self, no): + h = int(no / 60) + hs = "%d" %h + if h < 10: + hs = "0%d" %h + + m = int(no % 60) + ms = "%d" %m + if m < 10: + ms = "0%d" %m + + return hs, ms + + def general(self): + # normal table + tdSql.execute("create database wxy_db minrows 10 maxrows 200") + tdSql.execute("use wxy_db") + tdSql.execute("create table t1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp)") + for i in range(1, 1001): + hs, ms = self.genTime(i) + if i < 500: + ret = tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 1)" % (hs, ms, i)) + else: + ret = tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 0)" % (hs, ms, i)) + tdSql.query("select count(*) from t1") + tdSql.checkEqual(int(tdSql.getData(0, 0)), 1000) + + tdSql.execute("create database wxy_db_ns precision \"ns\"") + tdSql.execute("use wxy_db_ns") + tdSql.execute("create table t1 (ts timestamp, f float)") + tdSql.execute("insert into t1 values('2021-11-18 00:00:00.000000100', 1)" + "('2021-11-18 00:00:00.000000200', 2)" + "('2021-11-18 00:00:00.000000300', 3)" + "('2021-11-18 00:00:00.000000500', 4)") + + # super table + tdSql.execute("use wxy_db") + tdSql.execute("create stable st1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)") + tdSql.execute("create table st1s1 using st1 tags(1)") + tdSql.execute("create table st1s2 using st1 tags(2)") + for i in range(1, 1001): + hs, ms = self.genTime(i) + if 0 == i % 2: + ret = tdSql.execute("insert into st1s1(ts, i) values (\"2021-11-22 %s:%s:00\", %d)" % (hs, ms, i)) + else: + ret = tdSql.execute("insert into st1s2(ts, i) values (\"2021-11-22 %s:%s:00\", %d)" % (hs, ms, i)) + tdSql.query("select count(*) from st1s1") + tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) + tdSql.query("select count(*) from st1s2") + tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) + + def run(self): + tdSql.prepare() + self.general() + ElapsedCase().run() + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/elapsed.py b/tests/pytest/functions/function_elapsed_case.py similarity index 89% rename from tests/pytest/query/elapsed.py rename to tests/pytest/functions/function_elapsed_case.py index 5dc54ec928e40992b9787da0ede5f9d39f18b124..e05d6017f2f5466de06ca716b458caaf95535c51 100644 --- a/tests/pytest/query/elapsed.py +++ b/tests/pytest/functions/function_elapsed_case.py @@ -17,61 +17,9 @@ from util.log import * from util.cases import * from util.sql import * -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - - def genTime(self, no): - h = int(no / 60) - hs = "%d" %h - if h < 10: - hs = "0%d" %h - - m = int(no % 60) - ms = "%d" %m - if m < 10: - ms = "0%d" %m - - return hs, ms - - def general(self): - # normal table - tdSql.execute("create database wxy_db minrows 10 maxrows 200") - tdSql.execute("use wxy_db") - tdSql.execute("create table t1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp)") - for i in range(1, 1001): - hs, ms = self.genTime(i) - if i < 500: - ret = tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 1)" % (hs, ms, i)) - else: - ret = tdSql.execute("insert into t1(ts, i, b) values (\"2021-11-22 %s:%s:00\", %d, 0)" % (hs, ms, i)) - tdSql.query("select count(*) from t1") - tdSql.checkEqual(int(tdSql.getData(0, 0)), 1000) - - tdSql.execute("create database wxy_db_ns precision \"ns\"") - tdSql.execute("use wxy_db_ns") - tdSql.execute("create table t1 (ts timestamp, f float)") - tdSql.execute("insert into t1 values('2021-11-18 00:00:00.000000100', 1)" - "('2021-11-18 00:00:00.000000200', 2)" - "('2021-11-18 00:00:00.000000300', 3)" - "('2021-11-18 00:00:00.000000500', 4)") - - # super table - tdSql.execute("use wxy_db") - tdSql.execute("create stable st1(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)") - tdSql.execute("create table st1s1 using st1 tags(1)") - tdSql.execute("create table st1s2 using st1 tags(2)") - for i in range(1, 1001): - hs, ms = self.genTime(i) - if 0 == i % 2: - ret = tdSql.execute("insert into st1s1(ts, i) values (\"2021-11-22 %s:%s:00\", %d)" % (hs, ms, i)) - else: - ret = tdSql.execute("insert into st1s2(ts, i) values (\"2021-11-22 %s:%s:00\", %d)" % (hs, ms, i)) - tdSql.query("select count(*) from st1s1") - tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) - tdSql.query("select count(*) from st1s2") - tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) +class ElapsedCase: + def __init__(self, restart = False): + self.restart = restart def selectTest(self): tdSql.execute("use wxy_db") @@ -355,6 +303,9 @@ class TDTestCase: def continuousQueryTest(self): tdSql.execute("use wxy_db") + if (self.restart): + tdSql.execute("drop table elapsed_t") + tdSql.execute("drop table elapsed_st") tdSql.execute("create table elapsed_t as select elapsed(ts) from t1 interval(1m) sliding(30s)") tdSql.execute("create table elapsed_st as select elapsed(ts) from st1 interval(1m) sliding(30s) group by tbname") @@ -398,8 +349,6 @@ class TDTestCase: tdSql.error("select elapsed(ts), round(i) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") def run(self): - tdSql.prepare() - self.general() self.selectTest() self.whereTest() self.sessionTest() @@ -414,10 +363,3 @@ class TDTestCase: self.joinTest() self.unionAllTest() self.continuousQueryTest() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_elapsed_restart.py b/tests/pytest/functions/function_elapsed_restart.py new file mode 100644 index 0000000000000000000000000000000000000000..8b492267abdd8ea2d2b2fc27ee2e957e1038f48d --- /dev/null +++ b/tests/pytest/functions/function_elapsed_restart.py @@ -0,0 +1,35 @@ +################################################################### +# Copyright (c) 2020 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +from util.cases import * +from util.sql import * +from functions.function_elapsed_case import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def run(self): + tdSql.prepare() + ElapsedCase(True).run() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase())