more test case

This commit is contained in:
Hongze Cheng 2024-11-29 16:33:10 +08:00
parent 9f6f82ff98
commit 9d96009b1b
1 changed files with 75 additions and 12 deletions

View File

@ -21,17 +21,7 @@ import taos
class TDTestCase:
# Test cases ======================
def compactVgroupsSqlTest(self):
# create database db1
sql = "create database db1 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)
# create database db2
sql = "create database db2 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)
def compactVgroupsErrorTest(self):
# invalid sql
sql = "compact vgroups;"
tdLog.info(f"expect error SQL: {sql}")
@ -71,6 +61,66 @@ class TDTestCase:
sql = "compact db1.vgroups in (2, 5, 8)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)
def waitCompactFinish(self):
while True:
sql = 'show compacts'
rows = tdSql.query(sql)
if rows == 0:
break
time.sleep(1)
def compactVgroupsSqlTest(self):
# make sure there is no compacts
sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 0)
# use db1 and compact with db name should be ok
sql = 'use db1'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)
sql = 'compact vgroups in (2)'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)
# check there should be one row in compacts
sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)
compactId = tdSql.getData(0, 0)
# query the compact status
sql = f'show compact {compactId}'
tdLog.info(f'expect success SQL: {sql}')
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)
tdSql.checkEqual(tdSql.getData(0, 0), compactId) # compact_id
tdSql.checkEqual(tdSql.getData(0, 1), 2) # vgroup_id
# wait for compact finish
self.waitCompactFinish()
# start a new compact
sql = 'compact db2.vgroups in (7, 10)'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)
sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)
compactId = tdSql.getData(0, 0)
sql = f'show compact {compactId}'
tdLog.info(f'expect success SQL: {sql}')
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 2)
tdSql.checkEqual(tdSql.getData(0, 1) in (7, 10), True)
tdSql.checkEqual(tdSql.getData(1, 1) in (7, 10), True)
tdSql.checkEqual(tdSql.getData(0, 1) != tdSql.getData(1, 1), True)
# Test Framework Apis
def init(self, conn, logSql, replicaVar=1):
@ -80,7 +130,20 @@ class TDTestCase:
tdSql.init(conn.cursor(), True)
def run(self):
# do compact vgroups test
# create database db1
sql = "create database db1 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)
# create database db2
sql = "create database db2 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)
# error test
self.compactVgroupsErrorTest()
# success to compact vgroups
self.compactVgroupsSqlTest()
def stop(self):