update test case

This commit is contained in:
yihaoDeng 2024-11-28 21:17:57 +08:00
parent 1041e8e5b1
commit 43bfd83c56
1 changed files with 86 additions and 4 deletions

View File

@ -8,8 +8,41 @@ from util.common import *
from util.log import *
from util.sql import *
from util.sqlset import *
import os
import subprocess
def get_disk_usage(path):
try:
result = subprocess.run(['du', '-sb', path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0:
# The output is in the format "size\tpath"
size = int(result.stdout.split()[0])
return size
else:
print(f"Error: {result.stderr}")
return None
except Exception as e:
print(f"Exception occurred: {e}")
return None
def list_directories_with_keyword(base_path, keyword):
matching_dirs = []
for dirpath, dirnames, filenames in os.walk(base_path):
for dirname in dirnames:
if keyword in dirname:
full_path = os.path.join(dirpath, dirname)
matching_dirs.append(full_path)
return matching_dirs
def calculate_directories_size(base_path, keyword):
matching_dirs = list_directories_with_keyword(base_path, keyword)
total_size = 0
for directory in matching_dirs:
printf("directory: %s" % directory)
size = get_disk_usage(directory)
if size is not None:
total_size += size
return int(total_size/1024)
class TDTestCase:
"""This test case is used to veirfy show db disk usage"""
@ -20,12 +53,13 @@ class TDTestCase:
tdSql.init(conn.cursor())
self.dbname = "db_disk_usage"
self.stname = "st"
self.ctnum = 100
self.ctnum = 1000
self.row_num = 1000
self.row_data_size = self.ctnum * self.row_num * (8 + 4 + 4) # timestamp + int + float
self.other_dbname = "db_disk_usage_other"
self.other_stname = "st_other"
self.data_path = tdCom.getTaosdPath()
tdLog.debug("data_path: %s" % self.data_path)
# create database
tdSql.execute(f'create database if not exists {self.dbname};')
tdSql.execute(f'create database if not exists {self.other_dbname};')
@ -48,7 +82,16 @@ class TDTestCase:
tdSql.execute(f"flush database {self.dbname};")
tdLog.debug("init finished")
def getWALSize(self):
return calculate_directories_size(self.data_path, "wal")
def getTSDBSize(self):
tsdbDirSize = calculate_directories_size(self.data_path, "tsdb")
cacheRdbSize = calculate_directories_size(self.data_path, "cache.rdb")
return tsdbDirSize - cacheRdbSize
def getTableMetaSize(self):
return calculate_directories_size(self.data_path, "meta")
def getCacheRDBSize(self):
return calculate_directories_size(self.data_path, "cache.rdb")
def checkRes(self, queryRes):
disk_occupied = 0
compress_radio = 0
@ -71,13 +114,18 @@ class TDTestCase:
for i in range(self.ctnum):
tdSql.execute(f'create table ct_{str(i+1)} using {self.stname} tags ("name{str(i+1)}");')
sql = f"insert into ct_{str(i+1)} values "
for j in range(self.row_num * 2):
for j in range(self.row_num * 10):
sql += f"(now+{j+1}s, {j+1}, {random.uniform(15, 30)}) "
sql += ";"
tdSql.execute(sql)
tdSql.execute(f"flush database {self.other_dbname};")
tdLog.debug("init finished")
def value_check(self,base_value,check_value, threshold):
if abs(base_value-check_value) < threshold:
tdLog.info(f"checkEqual success, base_value={base_value},check_value={check_value}")
else :
tdLog.exit(f"checkEqual error, base_value=={base_value},check_value={check_value}")
def run(self):
@ -122,6 +170,40 @@ class TDTestCase:
tdSql.query(f"select sum(data1+data2+data3) from information_schema.ins_disk_usage where db_name='{self.other_dbname}';")
tdSql.checkData(0,0,disk_occupied)
tdSql.query(f"select sum(wal) from information_schema.ins_disk_usage where db_name='{self.other_dbname}' or db_name='{self.dbname}';")
tdSql.checkRows(1)
iwal = tdSql.queryResult[0][0]
tdSql.query(f"select sum(table_meta) from information_schema.ins_disk_usage where db_name='{self.other_dbname}' or db_name='{self.dbname}';")
itableMeta = tdSql.queryResult[0][0]
tdSql.query(f"select sum(data1+data2+data3) from information_schema.ins_disk_usage where db_name='{self.other_dbname}' or db_name='{self.dbname}';")
itsdbSize = int(tdSql.queryResult[0][0])
tdSql.query(f"select sum(cache_rdb) from information_schema.ins_disk_usage where db_name='{self.other_dbname}' or db_name='{self.dbname}';")
icache = tdSql.queryResult[0][0]
walSize = self.getWALSize()
tableMetaSize = self.getTableMetaSize()
tsdbSize = self.getTSDBSize()
cacheRdbSize = self.getCacheRDBSize()
tdLog.debug("calc: walSize: %s, tableMetaSize: %s, tsdbSize: %s, cacheRdbSize: %s" % (iwal, itableMeta, itsdbSize, icache))
tdLog.debug("du: walSize: %s, tableMetaSize: %s, tsdbSize: %s, cacheRdbSize: %s" % (walSize, tableMetaSize, tsdbSize, cacheRdbSize))
self.value_check(icache, cacheRdbSize, 64)
self.value_check(itableMeta,tableMetaSize, 64)
self.value_check(itsdbSize, tsdbSize, 64)
self.value_check(iwal, walSize, 128)
#if abs(icache - cacheRdbSize) > 12:
# tdLog.error("cache_rdb size is not equal")
#if abs(walSize - iwal) > 12:
# tdLog.error("wal size is not equal")
#if abs(tableMetaSize - itableMeta) > 12:
# tdLog.error("table_meta size is not equal")
#if abs(tsdbSize - itsdbSize) > 12:
# tdLog.error("tsdb size is not equal")
def stop(self):