Merge pull request #28347 from taosdata/test/3.0/TD-32536
test:Add a function to verify the consistency between the expected result file and the actual output file
This commit is contained in:
commit
8bb68adbcb
|
@ -18,6 +18,7 @@ import time
|
|||
import socket
|
||||
import json
|
||||
import toml
|
||||
import subprocess
|
||||
from frame.boundary import DataBoundary
|
||||
import taos
|
||||
from frame.log import *
|
||||
|
@ -1830,6 +1831,51 @@ class TDCom:
|
|||
if i == 1:
|
||||
self.record_history_ts = ts_value
|
||||
|
||||
def generate_query_result(self, inputfile, test_case):
|
||||
if not os.path.exists(inputfile):
|
||||
tdLog.exit(f"Input file '{inputfile}' does not exist.")
|
||||
else:
|
||||
self.query_result_file = f"./temp_{test_case}.result"
|
||||
os.system(f"taos -f {inputfile} | grep -v 'Query OK'|grep -v 'Copyright'| grep -v 'Welcome to the TDengine Command' > {self.query_result_file} ")
|
||||
return self.query_result_file
|
||||
|
||||
def compare_result_files(self, file1, file2):
|
||||
|
||||
try:
|
||||
# use subprocess.run to execute diff/fc commands
|
||||
# print(file1, file2)
|
||||
if platform.system().lower() != 'windows':
|
||||
cmd='diff'
|
||||
result = subprocess.run([cmd, "-u", "--color", file1, file2], text=True, capture_output=True)
|
||||
else:
|
||||
cmd='fc'
|
||||
result = subprocess.run([cmd, file1, file2], text=True, capture_output=True)
|
||||
# if result is not empty, print the differences and files name. Otherwise, the files are identical.
|
||||
if result.stdout:
|
||||
tdLog.debug(f"Differences between {file1} and {file2}")
|
||||
tdLog.notice(f"\r\n{result.stdout}")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
tdLog.debug("The 'diff' command is not found. Please make sure it's installed and available in your PATH.")
|
||||
except Exception as e:
|
||||
tdLog.debug(f"An error occurred: {e}")
|
||||
|
||||
|
||||
def compare_testcase_result(self, inputfile,expected_file,test_case):
|
||||
test_reulst_file = self.generate_query_result(inputfile,test_case)
|
||||
|
||||
if self.compare_result_files(expected_file, test_reulst_file ):
|
||||
tdLog.info("Test passed: Result files are identical.")
|
||||
os.system(f"rm -f {test_reulst_file}")
|
||||
else:
|
||||
caller = inspect.getframeinfo(inspect.stack()[1][0])
|
||||
tdLog.exit(f"{caller.lineno}(line:{caller.lineno}) failed: sqlfile is {inputfile}, expect_file:{expected_file} != reult_file:{test_reulst_file} ")
|
||||
|
||||
tdLog.exit("Test failed: Result files are different.")
|
||||
|
||||
|
||||
def is_json(msg):
|
||||
if isinstance(msg, str):
|
||||
try:
|
||||
|
@ -1864,4 +1910,6 @@ def dict2toml(in_dict: dict, file:str):
|
|||
with open(file, 'w') as f:
|
||||
toml.dump(in_dict, f)
|
||||
|
||||
|
||||
|
||||
tdCom = TDCom()
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
|
||||
taos> select pi()
|
||||
pi() |
|
||||
============================
|
||||
3.141592653589793 |
|
||||
|
||||
taos> select pi() + 1
|
||||
pi() + 1 |
|
||||
============================
|
||||
4.141592653589793 |
|
||||
|
||||
taos> select pi() - 1
|
||||
pi() - 1 |
|
||||
============================
|
||||
2.141592653589793 |
|
||||
|
||||
taos> select pi() * 2
|
||||
pi() * 2 |
|
||||
============================
|
||||
6.283185307179586 |
|
||||
|
||||
taos> select pi() / 2
|
||||
pi() / 2 |
|
||||
============================
|
||||
1.570796326794897 |
|
||||
|
||||
taos> select pi() from ts_4893.meters limit 5
|
||||
pi() |
|
||||
============================
|
||||
3.141592653589793 |
|
||||
3.141592653589793 |
|
||||
3.141592653589793 |
|
||||
3.141592653589793 |
|
||||
3.141592653589793 |
|
||||
|
||||
taos> select pi() + 1 from ts_4893.meters limit 1
|
||||
pi() + 1 |
|
||||
============================
|
||||
4.141592653589793 |
|
||||
|
||||
taos> select pi() - 1 from ts_4893.meters limit 1
|
||||
pi() - 1 |
|
||||
============================
|
||||
2.141592653589793 |
|
||||
|
||||
taos> select pi() * 2 from ts_4893.meters limit 1
|
||||
pi() * 2 |
|
||||
============================
|
||||
6.283185307179586 |
|
||||
|
||||
taos> select pi() / 2 from ts_4893.meters limit 1
|
||||
pi() / 2 |
|
||||
============================
|
||||
1.570796326794897 |
|
||||
|
||||
taos> select pi() + pi() from ts_4893.meters limit 1
|
||||
pi() + pi() |
|
||||
============================
|
||||
6.283185307179586 |
|
||||
|
||||
taos> select pi() - pi() from ts_4893.meters limit 1
|
||||
pi() - pi() |
|
||||
============================
|
||||
0.000000000000000 |
|
||||
|
||||
taos> select pi() * pi() from ts_4893.meters limit 1
|
||||
pi() * pi() |
|
||||
============================
|
||||
9.869604401089358 |
|
||||
|
||||
taos> select pi() / pi() from ts_4893.meters limit 1
|
||||
pi() / pi() |
|
||||
============================
|
||||
1.000000000000000 |
|
||||
|
||||
taos> select pi() + id from ts_4893.meters order by ts limit 5
|
||||
pi() + id |
|
||||
============================
|
||||
3.141592653589793 |
|
||||
4.141592653589793 |
|
||||
5.141592653589793 |
|
||||
6.141592653589793 |
|
||||
7.141592653589793 |
|
||||
|
||||
taos> select abs(pi())
|
||||
abs(pi()) |
|
||||
============================
|
||||
3.141592653589793 |
|
||||
|
||||
taos> select pow(pi(), 2)
|
||||
pow(pi(), 2) |
|
||||
============================
|
||||
9.869604401089358 |
|
||||
|
||||
taos> select sqrt(pi())
|
||||
sqrt(pi()) |
|
||||
============================
|
||||
1.772453850905516 |
|
||||
|
||||
taos> select cast(pi() as int)
|
||||
cast(pi() as int) |
|
||||
====================
|
||||
3 |
|
||||
|
||||
taos> select pi()
|
||||
pi() |
|
||||
============================
|
||||
3.141592653589793 |
|
||||
|
||||
taos> select substring_index(null, '.', 2)
|
||||
substring_index(null, '.', 2) |
|
||||
================================
|
||||
NULL |
|
||||
|
Can't render this file because it has a wrong number of fields in line 90.
|
|
@ -1,20 +1,21 @@
|
|||
select pi();
|
||||
select pi() + 1;
|
||||
select pi() - 1;
|
||||
select pi() * 2;
|
||||
select pi() / 2;
|
||||
select pi() from ts_4893.meters limit 5;
|
||||
select pi() + 1 from ts_4893.meters limit 1;
|
||||
select pi() - 1 from ts_4893.meters limit 1;
|
||||
select pi() * 2 from ts_4893.meters limit 1;
|
||||
select pi() / 2 from ts_4893.meters limit 1;
|
||||
select pi() + pi() from ts_4893.meters limit 1;
|
||||
select pi() - pi() from ts_4893.meters limit 1;
|
||||
select pi() * pi() from ts_4893.meters limit 1;
|
||||
select pi() / pi() from ts_4893.meters limit 1;
|
||||
select pi() + id from ts_4893.meters order by ts limit 5;
|
||||
select abs(pi());
|
||||
select pow(pi(), 2);
|
||||
select sqrt(pi());
|
||||
select cast(pi() as int);
|
||||
select pi();
|
||||
select pi()
|
||||
select pi() + 1
|
||||
select pi() - 1
|
||||
select pi() * 2
|
||||
select pi() / 2
|
||||
select pi() from ts_4893.meters limit 5
|
||||
select pi() + 1 from ts_4893.meters limit 1
|
||||
select pi() - 1 from ts_4893.meters limit 1
|
||||
select pi() * 2 from ts_4893.meters limit 1
|
||||
select pi() / 2 from ts_4893.meters limit 1
|
||||
select pi() + pi() from ts_4893.meters limit 1
|
||||
select pi() - pi() from ts_4893.meters limit 1
|
||||
select pi() * pi() from ts_4893.meters limit 1
|
||||
select pi() / pi() from ts_4893.meters limit 1
|
||||
select pi() + id from ts_4893.meters order by ts limit 5
|
||||
select abs(pi())
|
||||
select pow(pi(), 2)
|
||||
select sqrt(pi())
|
||||
select cast(pi() as int)
|
||||
select pi()
|
||||
select substring_index(null, '.', 2)
|
||||
|
|
|
@ -17,14 +17,15 @@ import random
|
|||
|
||||
import taos
|
||||
import frame
|
||||
import frame.etool
|
||||
|
||||
from frame.etool import *
|
||||
from frame.log import *
|
||||
from frame.cases import *
|
||||
from frame.sql import *
|
||||
from frame.caseBase import *
|
||||
from frame import *
|
||||
|
||||
from frame import etool
|
||||
from frame.common import *
|
||||
|
||||
class TDTestCase(TBase):
|
||||
updatecfgDict = {
|
||||
|
@ -84,8 +85,16 @@ class TDTestCase(TBase):
|
|||
tdSql.error(err_statement)
|
||||
err_statement = ''
|
||||
|
||||
def test_normal_query_new(self, testCase):
|
||||
# read sql from .sql file and execute
|
||||
tdLog.info(f"test normal query.")
|
||||
self.sqlFile = etool.curFile(__file__, f"in/{testCase}.in")
|
||||
self.ansFile = etool.curFile(__file__, f"ans/{testCase}_1.csv")
|
||||
|
||||
tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase)
|
||||
|
||||
def test_pi(self):
|
||||
self.test_normal_query("pi")
|
||||
self.test_normal_query_new("pi")
|
||||
|
||||
def test_round(self):
|
||||
self.test_normal_query("round")
|
||||
|
|
|
@ -24,45 +24,6 @@ class TDTestCase:
|
|||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor())
|
||||
|
||||
#tdSql.init(conn.cursor(), logSql) # output sql.txt file
|
||||
|
||||
# def consume_TS_4674_Test(self):
|
||||
#
|
||||
# os.system("nohup taosBenchmark -y -B 1 -t 4 -S 1000 -n 1000000 -i 1000 -v 1 -a 3 > /dev/null 2>&1 &")
|
||||
# time.sleep()
|
||||
# tdSql.execute(f'create topic topic_all with meta as database test')
|
||||
# consumer_dict = {
|
||||
# "group.id": "g1",
|
||||
# "td.connect.user": "root",
|
||||
# "td.connect.pass": "taosdata",
|
||||
# "auto.offset.reset": "earliest",
|
||||
# }
|
||||
# consumer = Consumer(consumer_dict)
|
||||
#
|
||||
# try:
|
||||
# consumer.subscribe(["topic_all"])
|
||||
# except TmqError:
|
||||
# tdLog.exit(f"subscribe error")
|
||||
#
|
||||
# try:
|
||||
# while True:
|
||||
# res = consumer.poll(5)
|
||||
# if not res:
|
||||
# print(f"null")
|
||||
# continue
|
||||
# val = res.value()
|
||||
# if val is None:
|
||||
# print(f"null")
|
||||
# continue
|
||||
# cnt = 0;
|
||||
# for block in val:
|
||||
# cnt += len(block.fetchall())
|
||||
#
|
||||
# print(f"block {cnt} rows")
|
||||
#
|
||||
# finally:
|
||||
# consumer.close()
|
||||
|
||||
def get_leader(self):
|
||||
tdLog.debug("get leader")
|
||||
tdSql.query("show vnodes")
|
||||
|
@ -74,19 +35,20 @@ class TDTestCase:
|
|||
|
||||
def balance_vnode(self):
|
||||
leader_before = self.get_leader()
|
||||
|
||||
tdSql.query("balance vgroup leader")
|
||||
while True:
|
||||
leader_after = -1
|
||||
tdSql.query("balance vgroup leader")
|
||||
tdLog.debug("balancing vgroup leader")
|
||||
while True:
|
||||
tdLog.debug("get new vgroup leader")
|
||||
leader_after = self.get_leader()
|
||||
if leader_after != -1 :
|
||||
break;
|
||||
break
|
||||
else:
|
||||
time.sleep(1)
|
||||
if leader_after != leader_before:
|
||||
tdLog.debug("leader changed")
|
||||
break;
|
||||
break
|
||||
else :
|
||||
time.sleep(1)
|
||||
|
||||
|
@ -115,7 +77,7 @@ class TDTestCase:
|
|||
except TmqError:
|
||||
tdLog.exit(f"subscribe error")
|
||||
|
||||
cnt = 0;
|
||||
cnt = 0
|
||||
balance = False
|
||||
try:
|
||||
while True:
|
||||
|
|
Loading…
Reference in New Issue