Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
456ea712
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
456ea712
编写于
5月 11, 2021
作者:
S
Steven Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored crash_gen tool with stronger typing
上级
7e1b1b1f
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
169 addition
and
137 deletion
+169
-137
tests/pytest/crash_gen/__init__.py
tests/pytest/crash_gen/__init__.py
+0
-4
tests/pytest/crash_gen/crash_gen_main.py
tests/pytest/crash_gen/crash_gen_main.py
+94
-90
tests/pytest/crash_gen/service_manager.py
tests/pytest/crash_gen/service_manager.py
+13
-20
tests/pytest/crash_gen/shared/config.py
tests/pytest/crash_gen/shared/config.py
+18
-5
tests/pytest/crash_gen/shared/db.py
tests/pytest/crash_gen/shared/db.py
+13
-6
tests/pytest/crash_gen/shared/misc.py
tests/pytest/crash_gen/shared/misc.py
+3
-7
tests/pytest/crash_gen/shared/types.py
tests/pytest/crash_gen/shared/types.py
+28
-0
tests/pytest/crash_gen/types.py
tests/pytest/crash_gen/types.py
+0
-5
未找到文件。
tests/pytest/crash_gen/__init__.py
浏览文件 @
456ea712
# Helpful Ref: https://stackoverflow.com/questions/24100558/how-can-i-split-a-module-into-multiple-files-without-breaking-a-backwards-compa/24100645
# Helpful Ref: https://stackoverflow.com/questions/24100558/how-can-i-split-a-module-into-multiple-files-without-breaking-a-backwards-compa/24100645
from
crash_gen.service_manager
import
ServiceManager
,
TdeInstance
,
TdeSubProcess
from
crash_gen.service_manager
import
ServiceManager
,
TdeInstance
,
TdeSubProcess
from
crash_gen.misc
import
Logging
,
Status
,
CrashGenError
,
Dice
,
Helper
,
Progress
from
crash_gen.db
import
DbConn
,
MyTDSql
,
DbConnNative
,
DbManager
from
crash_gen.settings
import
Settings
from
crash_gen.types
import
DirPath
\ No newline at end of file
tests/pytest/crash_gen/crash_gen_main.py
浏览文件 @
456ea712
此差异已折叠。
点击以展开。
tests/pytest/crash_gen/service_manager.py
浏览文件 @
456ea712
...
@@ -19,10 +19,15 @@ except:
...
@@ -19,10 +19,15 @@ except:
sys
.
exit
(
-
1
)
sys
.
exit
(
-
1
)
from
queue
import
Queue
,
Empty
from
queue
import
Queue
,
Empty
from
crash_gen.misc
import
CrashGenError
,
Dice
,
Helper
,
Logging
,
Progress
,
Status
from
.shared.config
import
Config
from
crash_gen.db
import
DbConn
,
DbTarget
from
.shared.db
import
DbTarget
,
DbConn
from
crash_gen.settings
import
Settings
from
.shared.misc
import
Logging
,
Helper
,
CrashGenError
,
Status
,
Progress
,
Dice
from
crash_gen.types
import
DirPath
from
.shared.types
import
DirPath
# from crash_gen.misc import CrashGenError, Dice, Helper, Logging, Progress, Status
# from crash_gen.db import DbConn, DbTarget
# from crash_gen.settings import Config
# from crash_gen.types import DirPath
class
TdeInstance
():
class
TdeInstance
():
"""
"""
...
@@ -173,7 +178,7 @@ quorum 2
...
@@ -173,7 +178,7 @@ quorum 2
def
getServiceCmdLine
(
self
):
# to start the instance
def
getServiceCmdLine
(
self
):
# to start the instance
cmdLine
=
[]
cmdLine
=
[]
if
Settings
.
getConfig
().
track_memory_leaks
:
if
Config
.
getConfig
().
track_memory_leaks
:
Logging
.
info
(
"Invoking VALGRIND on service..."
)
Logging
.
info
(
"Invoking VALGRIND on service..."
)
cmdLine
=
[
'valgrind'
,
'--leak-check=yes'
]
cmdLine
=
[
'valgrind'
,
'--leak-check=yes'
]
# TODO: move "exec -c" into Popen(), we can both "use shell" and NOT fork so ask to lose kill control
# TODO: move "exec -c" into Popen(), we can both "use shell" and NOT fork so ask to lose kill control
...
@@ -789,22 +794,10 @@ class ServiceManagerThread:
...
@@ -789,22 +794,10 @@ class ServiceManagerThread:
def
stop
(
self
):
def
stop
(
self
):
# can be called from both main thread or signal handler
# can be called from both main thread or signal handler
# Linux will send Control-C generated SIGINT to the TDengine process
# Linux will send Control-C generated SIGINT to the TDengine process already, ref:
# already, ref:
# https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
# https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
# if not self._tdeSubProcess:
# raise RuntimeError("sub process object missing")
self
.
join
()
# stop the thread, status change moved to TdeSubProcess
# self._status.set(Status.STATUS_STOPPING)
# TdeSubProcess.stop(self._tdeSubProcess) # must stop, no matter what
# self._tdeSubProcess = None
# if not self._tdeSubProcess.stop(): # everything withing
# if self._tdeSubProcess.isRunning(): # still running, should now never happen
# Logging.error("FAILED to stop sub process, it is still running... pid = {}".format(
# self._tdeSubProcess.getPid()))
# else:
# self._tdeSubProcess = None # not running any more
self
.
join
()
# stop the thread, change the status, etc.
# Check if it's really stopped
# Check if it's really stopped
outputLines
=
10
# for last output
outputLines
=
10
# for last output
...
...
tests/pytest/crash_gen/s
ettings
.py
→
tests/pytest/crash_gen/s
hared/config
.py
浏览文件 @
456ea712
from
__future__
import
annotations
from
__future__
import
annotations
import
argparse
import
argparse
from
typing
import
Optional
from
typing
import
Optional
from
crash_gen.misc
import
CrashGenError
from
.misc
import
CrashGenError
# from crash_gen.misc import CrashGenError
# gConfig: Optional[argparse.Namespace]
# gConfig: Optional[argparse.Namespace]
class
Settings
:
class
Config
:
_config
=
None
# type Optional[argparse.Namespace]
_config
=
None
# type Optional[argparse.Namespace]
@
classmethod
@
classmethod
def
init
(
cls
):
def
init
(
cls
,
parser
:
argparse
.
ArgumentParser
):
cls
.
_config
=
None
if
cls
.
_config
is
not
None
:
raise
CrashGenError
(
"Config can only be initialized once"
)
cls
.
_config
=
parser
.
parse_args
()
# print(cls._config)
@
classmethod
@
classmethod
def
setConfig
(
cls
,
config
:
argparse
.
Namespace
):
def
setConfig
(
cls
,
config
:
argparse
.
Namespace
):
...
@@ -26,4 +32,11 @@ class Settings:
...
@@ -26,4 +32,11 @@ class Settings:
@
classmethod
@
classmethod
def
clearConfig
(
cls
):
def
clearConfig
(
cls
):
cls
.
_config
=
None
cls
.
_config
=
None
\ No newline at end of file
@
classmethod
def
isSet
(
cls
,
cfgKey
):
cfg
=
cls
.
getConfig
()
if
cfgKey
not
in
cfg
:
return
False
return
cfg
.
__getattribute__
(
cfgKey
)
\ No newline at end of file
tests/pytest/crash_gen/db.py
→
tests/pytest/crash_gen/
shared/
db.py
浏览文件 @
456ea712
from
__future__
import
annotations
from
__future__
import
annotations
import
sys
import
sys
import
os
import
datetime
import
time
import
time
import
threading
import
threading
import
requests
import
requests
from
requests.auth
import
HTTPBasicAuth
from
requests.auth
import
HTTPBasicAuth
from
crash_gen.types
import
QueryResult
import
taos
import
taos
from
util.sql
import
*
from
util.sql
import
*
...
@@ -13,13 +15,12 @@ from util.cases import *
...
@@ -13,13 +15,12 @@ from util.cases import *
from
util.dnodes
import
*
from
util.dnodes
import
*
from
util.log
import
*
from
util.log
import
*
from
.misc
import
Logging
,
CrashGenError
,
Helper
,
Dice
import
os
import
datetime
import
traceback
import
traceback
# from .service_manager import TdeInstance
# from .service_manager import TdeInstance
from
crash_gen.settings
import
Settings
from
.config
import
Config
from
.misc
import
Logging
,
CrashGenError
,
Helper
from
.types
import
QueryResult
class
DbConn
:
class
DbConn
:
TYPE_NATIVE
=
"native-c"
TYPE_NATIVE
=
"native-c"
...
@@ -250,7 +251,13 @@ class MyTDSql:
...
@@ -250,7 +251,13 @@ class MyTDSql:
def
_execInternal
(
self
,
sql
):
def
_execInternal
(
self
,
sql
):
startTime
=
time
.
time
()
startTime
=
time
.
time
()
# Logging.debug("Executing SQL: " + sql)
# Logging.debug("Executing SQL: " + sql)
# ret = None # TODO: use strong type here
# try: # Let's not capture the error, and let taos.error.ProgrammingError pass through
ret
=
self
.
_cursor
.
execute
(
sql
)
ret
=
self
.
_cursor
.
execute
(
sql
)
# except taos.error.ProgrammingError as err:
# Logging.warning("Taos SQL execution error: {}, SQL: {}".format(err.msg, sql))
# raise CrashGenError(err.msg)
# print("\nSQL success: {}".format(sql))
# print("\nSQL success: {}".format(sql))
queryTime
=
time
.
time
()
-
startTime
queryTime
=
time
.
time
()
-
startTime
# Record the query time
# Record the query time
...
@@ -262,7 +269,7 @@ class MyTDSql:
...
@@ -262,7 +269,7 @@ class MyTDSql:
cls
.
lqStartTime
=
startTime
cls
.
lqStartTime
=
startTime
# Now write to the shadow database
# Now write to the shadow database
if
Settings
.
getConfig
().
use_shadow_db
:
if
Config
.
isSet
(
'use_shadow_db'
)
:
if
sql
[:
11
]
==
"INSERT INTO"
:
if
sql
[:
11
]
==
"INSERT INTO"
:
if
sql
[:
16
]
==
"INSERT INTO db_0"
:
if
sql
[:
16
]
==
"INSERT INTO db_0"
:
sql2
=
"INSERT INTO db_s"
+
sql
[
16
:]
sql2
=
"INSERT INTO db_s"
+
sql
[
16
:]
...
...
tests/pytest/crash_gen/misc.py
→
tests/pytest/crash_gen/
shared/
misc.py
浏览文件 @
456ea712
...
@@ -47,7 +47,7 @@ class Logging:
...
@@ -47,7 +47,7 @@ class Logging:
return
cls
.
logger
return
cls
.
logger
@
classmethod
@
classmethod
def
clsInit
(
cls
,
gConfig
):
# TODO: refactor away gConfig
def
clsInit
(
cls
,
debugMode
:
bool
):
if
cls
.
logger
:
if
cls
.
logger
:
return
return
...
@@ -62,12 +62,8 @@ class Logging:
...
@@ -62,12 +62,8 @@ class Logging:
# print("setting logger variable")
# print("setting logger variable")
# global logger
# global logger
cls
.
logger
=
MyLoggingAdapter
(
_logger
,
{})
cls
.
logger
=
MyLoggingAdapter
(
_logger
,
{})
cls
.
logger
.
setLevel
(
logging
.
DEBUG
if
debugMode
else
logging
.
INFO
)
# default seems to be INFO
if
(
gConfig
.
debug
):
cls
.
logger
.
setLevel
(
logging
.
DEBUG
)
# default seems to be INFO
else
:
cls
.
logger
.
setLevel
(
logging
.
INFO
)
@
classmethod
@
classmethod
def
info
(
cls
,
msg
):
def
info
(
cls
,
msg
):
cls
.
logger
.
info
(
msg
)
cls
.
logger
.
info
(
msg
)
...
...
tests/pytest/crash_gen/shared/types.py
0 → 100644
浏览文件 @
456ea712
from
typing
import
Any
,
List
,
Dict
,
NewType
from
enum
import
Enum
DirPath
=
NewType
(
'DirPath'
,
str
)
QueryResult
=
NewType
(
'QueryResult'
,
List
[
List
[
Any
]])
class
TdDataType
(
Enum
):
'''
Use a Python Enum types of represent all the data types in TDengine.
Ref: https://www.taosdata.com/cn/documentation/taos-sql#data-type
'''
TIMESTAMP
=
'TIMESTAMP'
INT
=
'INT'
BIGINT
=
'BIGINT'
FLOAT
=
'FLOAT'
DOUBLE
=
'DOUBLE'
BINARY
=
'BINARY'
BINARY16
=
'BINARY(16)'
# TODO: get rid of this hack
BINARY200
=
'BINARY(200)'
SMALLINT
=
'SMALLINT'
TINYINT
=
'TINYINT'
BOOL
=
'BOOL'
NCHAR
=
'NCHAR'
TdColumns
=
Dict
[
str
,
TdDataType
]
TdTags
=
Dict
[
str
,
TdDataType
]
tests/pytest/crash_gen/types.py
已删除
100644 → 0
浏览文件 @
7e1b1b1f
from
typing
import
Any
,
List
,
NewType
DirPath
=
NewType
(
'DirPath'
,
str
)
QueryResult
=
NewType
(
'QueryResult'
,
List
[
List
[
Any
]])
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录