test: add test case for log output option

This commit is contained in:
kailixu 2024-12-01 18:12:16 +08:00
parent 57afdc6612
commit 09e1abc967
1 changed files with 103 additions and 66 deletions

View File

@ -1,66 +1,103 @@
import taos import taos
import sys import sys
import time import time
import os import os
from util.log import * from util.log import *
from util.sql import * from util.sql import *
from util.cases import * from util.cases import *
from util.dnodes import * from util.dnodes import *
class TDTestCase: class TDTestCase:
def init(self, conn, logSql, replicaVar=1): def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar) self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
tdSql.prepare()
def getBuildPath(self): self.buildPath = self.getBuildPath()
selfPath = os.path.dirname(os.path.realpath(__file__)) if (self.buildPath == ""):
tdLog.exit("taosd not found!")
if ("community" in selfPath): else:
projPath = selfPath[:selfPath.find("community")] tdLog.info("taosd found in %s" % self.buildPath)
else: self.logPath = self.buildPath + "/../sim/dnode1/log"
projPath = selfPath[:selfPath.find("tests")] tdLog.info("log path: %s" % self.logPath)
for root, dirs, files in os.walk(projPath): def getBuildPath(self):
if ("taosd" in files or "taosd.exe" in files): selfPath = os.path.dirname(os.path.realpath(__file__))
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("community" in selfPath):
buildPath = root[:len(root) - len("/build/bin")] projPath = selfPath[:selfPath.find("community")]
break else:
return buildPath projPath = selfPath[:selfPath.find("tests")]
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring for root, dirs, files in os.walk(projPath):
tdSql.prepare() if ("taosd" in files or "taosd.exe" in files):
# time.sleep(2) rootRealPath = os.path.dirname(os.path.realpath(root))
tdSql.query("create user testpy pass 'testpy'") if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
buildPath = self.getBuildPath() break
if (buildPath == ""): return buildPath
tdLog.exit("taosd not found!")
else: def logPathBasic(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
tdLog.info("taosd found in %s" % buildPath) tdSql.query("create user testpy pass 'testpy'")
logPath = buildPath + "/../sim/dnode1/log"
tdLog.info("log path: %s" % logPath) tdDnodes.stop(1)
time.sleep(2)
tdDnodes.stop(1) tdSql.error("select * from information_schema.ins_databases")
time.sleep(2) tdSql.checkRows(2)
tdSql.error("select * from information_schema.ins_databases") os.system("rm -rf %s" % self.logPath)
os.system("rm -rf %s" % logPath) if os.path.exists(self.logPath) == True:
if os.path.exists(logPath) == True: tdLog.exit("log path still exist!")
tdLog.exit("log pat still exist!")
tdDnodes.start(1)
tdDnodes.start(1) time.sleep(2)
time.sleep(2) if os.path.exists(self.logPath) != True:
if os.path.exists(logPath) != True: tdLog.exit("log path is not generated!")
tdLog.exit("log pat is not generated!")
tdSql.query("select * from information_schema.ins_databases")
tdSql.query("select * from information_schema.ins_databases") tdSql.checkRows(2)
def stop(self): def prepareCfg(self, cfgPath, cfgDict):
tdSql.close() with open(cfgPath + "/taos.cfg", "w") as f:
tdLog.success(f"{__file__} successfully executed") for key in cfgDict:
f.write("%s %s\n" % (key, cfgDict[key]))
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase()) def check_function_1(self):
# Implementation of check function 1
tdLog.info("Running check function 1")
# Add your check logic here
def check_function_2(self):
# Implementation of check function 2
tdLog.info("Running check function 2")
# Add your check logic here
def check_function_3(self):
# Implementation of check function 3
tdLog.info("Running check function 3")
# Add your check logic here
def prepareCheckFunctions(self):
self.check_functions = {
"check_function_1": self.check_function_1,
"check_function_2": self.check_function_2,
"check_function_3": self.check_function_3
}
def checkLogOutput(self):
self.prepareCheckFunctions()
for key, check_func in self.check_functions.items():
print(f"Running {key}")
check_func()
def run(self):
# self.logPathBasic()
self.checkLogOutput()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())