Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3d843d32
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3d843d32
编写于
4月 22, 2020
作者:
S
slguan
提交者:
GitHub
4月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1686 from taosdata/make-python-test-dynamically-load-module
make python test framework dynamically load module
上级
285a7e2d
fefccc3a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
113 addition
and
68 deletion
+113
-68
tests/pytest/insert/basic.py
tests/pytest/insert/basic.py
+12
-12
tests/pytest/simpletest.sh
tests/pytest/simpletest.sh
+2
-2
tests/pytest/test.py
tests/pytest/test.py
+5
-6
tests/pytest/util/cases.py
tests/pytest/util/cases.py
+77
-42
tests/pytest/util/dnodes.py
tests/pytest/util/dnodes.py
+17
-6
未找到文件。
tests/pytest/insert/basic.py
浏览文件 @
3d843d32
...
...
@@ -17,6 +17,7 @@ from util.log import *
from
util.cases
import
*
from
util.sql
import
*
class
TDTestCase
:
def
init
(
self
,
conn
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
...
...
@@ -24,25 +25,24 @@ class TDTestCase:
def
run
(
self
):
tdSql
.
prepare
()
tdSql
.
execute
(
'show databases'
)
tdSql
.
execute
(
'drop database if exists db'
)
tdSql
.
execute
(
'create database db'
)
tdSql
.
execute
(
'use db'
)
tdSql
.
execute
(
'create table tb (ts timestamp, speed int)'
)
ret
=
tdSql
.
execute
(
'create table tb (ts timestamp, speed int)'
)
insertRows
=
10
tdLog
.
info
(
"insert %d rows"
%
(
insertRows
))
for
i
in
range
(
0
,
insertRows
):
tdSql
.
execute
(
'insert into tb values (now + %dm, %d)'
%
(
i
,
i
))
ret
=
tdSql
.
execute
(
'insert into tb values (now + %dm, %d)'
%
(
i
,
i
))
#
tdLog.info("insert earlier data")
#
tdSql.execute('insert into tb values (now - 5m , 10)')
#
tdSql.execute('insert into tb values (now - 6m , 10)')
#
tdSql.execute('insert into tb values (now - 7m , 10)')
#
tdSql.execute('insert into tb values (now - 8m , 10)')
tdLog
.
info
(
"insert earlier data"
)
tdSql
.
execute
(
'insert into tb values (now - 5m , 10)'
)
tdSql
.
execute
(
'insert into tb values (now - 6m , 10)'
)
tdSql
.
execute
(
'insert into tb values (now - 7m , 10)'
)
tdSql
.
execute
(
'insert into tb values (now - 8m , 10)'
)
tdSql
.
query
(
"select * from tb"
)
tdSql
.
checkRows
(
insertRows
)
tdSql
.
checkRows
(
insertRows
+
4
)
def
stop
(
self
):
tdSql
.
close
()
...
...
tests/pytest/simpletest.sh
浏览文件 @
3d843d32
#!/bin/bash
python
2
./test.py
-f
insert/basic.py
$1
python
2
./test.py
-s
$1
python
3
./test.py
-f
insert/basic.py
$1
python
3
./test.py
-s
$1
tests/pytest/test.py
浏览文件 @
3d843d32
...
...
@@ -24,8 +24,6 @@ from util.cases import *
import
taos
# add testcase here:
from
insert.basic
import
*
if
__name__
==
"__main__"
:
fileName
=
"all"
...
...
@@ -35,7 +33,7 @@ if __name__ == "__main__":
valgrind
=
0
stop
=
0
opts
,
args
=
getopt
.
gnu_getopt
(
sys
.
argv
[
1
:],
'f:p:m:scgh'
,
[
'file='
,
'path='
,
'master'
,
'stop'
,
'cluster'
,
'valgrind'
,
'help'
])
'file='
,
'path='
,
'master'
,
'stop'
,
'cluster'
,
'valgrind'
,
'help'
])
for
key
,
value
in
opts
:
if
key
in
[
'-h'
,
'--help'
]:
tdLog
.
printNoPrefix
(
...
...
@@ -72,13 +70,13 @@ if __name__ == "__main__":
toBeKilled
=
"valgrind.bin"
killCmd
=
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -HUP "
%
toBeKilled
os
.
system
(
killCmd
)
time
.
sleep
(
1
)
#
os.system(killCmd)
#
time.sleep(1)
psCmd
=
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}'"
%
toBeKilled
processID
=
subprocess
.
check_output
(
psCmd
,
shell
=
True
)
while
(
processID
):
while
(
processID
):
os
.
system
(
killCmd
)
time
.
sleep
(
1
)
processID
=
subprocess
.
check_output
(
psCmd
,
shell
=
True
)
...
...
@@ -87,6 +85,7 @@ if __name__ == "__main__":
if
masterIp
==
""
:
tdDnodes
.
init
(
deployPath
)
tdDnodes
.
setTestCluster
(
testCluster
)
tdDnodes
.
setValgrind
(
valgrind
)
if
testCluster
:
...
...
tests/pytest/util/cases.py
浏览文件 @
3d843d32
...
...
@@ -15,6 +15,8 @@ import sys
import
os
import
time
import
datetime
import
inspect
import
importlib
from
util.log
import
*
...
...
@@ -30,6 +32,10 @@ class TDCases:
self
.
windowsCases
=
[]
self
.
clusterCases
=
[]
def
__dynamicLoadModule
(
self
,
fileName
):
moduleName
=
fileName
.
replace
(
".py"
,
""
).
replace
(
"/"
,
"."
)
return
importlib
.
import_module
(
moduleName
,
package
=
'..'
)
def
addWindows
(
self
,
name
,
case
):
self
.
windowsCases
.
append
(
TDCase
(
name
,
case
))
...
...
@@ -40,64 +46,93 @@ class TDCases:
self
.
clusterCases
.
append
(
TDCase
(
name
,
case
))
def
runAllLinux
(
self
,
conn
):
tdLog
.
notice
(
"run total %d cases"
%
(
len
(
self
.
linuxCases
)))
for
case
in
self
.
linuxCases
:
case
.
case
.
init
(
conn
)
case
.
case
.
run
()
case
.
case
.
stop
()
tdLog
.
notice
(
"total %d cases executed"
%
(
len
(
self
.
linuxCases
)))
# TODO: load all Linux cases here
runNum
=
0
for
tmp
in
self
.
linuxCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
case
=
testModule
.
TDTestCase
()
case
.
init
(
conn
)
case
.
run
()
case
.
stop
()
runNum
+=
1
continue
tdLog
.
notice
(
"total %d Linux test case(s) executed"
%
(
runNum
))
def
runOneLinux
(
self
,
conn
,
fileName
):
tdLog
.
notice
(
"run cases like %s"
%
(
fileName
))
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
runNum
=
0
for
case
in
self
.
linuxCases
:
if
case
.
name
.
find
(
fileName
)
!=
-
1
:
case
.
case
.
init
(
conn
)
case
.
case
.
run
(
)
case
.
case
.
stop
()
time
.
sleep
(
5
)
for
tmp
in
self
.
linuxCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
case
=
testModule
.
TDTestCase
(
)
case
.
init
(
conn
)
case
.
run
()
case
.
stop
(
)
runNum
+=
1
tdLog
.
notice
(
"total %d cases executed"
%
(
runNum
))
continue
tdLog
.
notice
(
"total %d Linux test case(s) executed"
%
(
runNum
))
def
runAllWindows
(
self
,
conn
):
tdLog
.
notice
(
"run total %d cases"
%
(
len
(
self
.
windowsCases
)))
for
case
in
self
.
windowsCases
:
case
.
case
.
init
(
conn
)
case
.
case
.
run
()
case
.
case
.
stop
()
tdLog
.
notice
(
"total %d cases executed"
%
(
len
(
self
.
windowsCases
)))
# TODO: load all Windows cases here
runNum
=
0
for
tmp
in
self
.
windowsCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
case
=
testModule
.
TDTestCase
()
case
.
init
(
conn
)
case
.
run
()
case
.
stop
()
runNum
+=
1
continue
tdLog
.
notice
(
"total %d Windows test case(s) executed"
%
(
runNum
))
def
runOneWindows
(
self
,
conn
,
fileName
):
tdLog
.
notice
(
"run cases like %s"
%
(
fileName
))
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
runNum
=
0
for
case
in
self
.
windowsCases
:
if
case
.
name
.
find
(
fileName
)
!=
-
1
:
case
.
case
.
init
(
conn
)
case
.
case
.
run
(
)
case
.
case
.
stop
()
time
.
sleep
(
2
)
for
tmp
in
self
.
windowsCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
case
=
testModule
.
TDTestCase
(
)
case
.
init
(
conn
)
case
.
run
()
case
.
stop
(
)
runNum
+=
1
tdLog
.
notice
(
"total %d cases executed"
%
(
runNum
))
continue
tdLog
.
notice
(
"total %d Windows case(s) executed"
%
(
runNum
))
def
runAllCluster
(
self
):
tdLog
.
notice
(
"run total %d cases"
%
(
len
(
self
.
clusterCases
)))
for
case
in
self
.
clusterCases
:
case
.
case
.
init
()
case
.
case
.
run
()
case
.
case
.
stop
()
tdLog
.
notice
(
"total %d cases executed"
%
(
len
(
self
.
clusterCases
)))
# TODO: load all cluster case module here
runNum
=
0
for
tmp
in
self
.
clusterCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
tdLog
.
notice
(
"run cases like %s"
%
(
fileName
))
case
=
testModule
.
TDTestCase
()
case
.
init
()
case
.
run
()
case
.
stop
()
runNum
+=
1
continue
tdLog
.
notice
(
"total %d Cluster test case(s) executed"
%
(
runNum
))
def
runOneCluster
(
self
,
fileName
):
tdLog
.
notice
(
"run cases like %s"
%
(
fileName
))
testModule
=
self
.
__dynamicLoadModule
(
fileName
)
runNum
=
0
for
case
in
self
.
clusterCases
:
if
case
.
name
.
find
(
fileName
)
!=
-
1
:
case
.
case
.
init
()
case
.
case
.
run
()
case
.
case
.
stop
()
time
.
sleep
(
2
)
for
tmp
in
self
.
clusterCases
:
if
tmp
.
name
.
find
(
fileName
)
!=
-
1
:
tdLog
.
notice
(
"run cases like %s"
%
(
fileName
))
case
=
testModule
.
TDTestCase
()
case
.
init
()
case
.
run
()
case
.
stop
()
runNum
+=
1
tdLog
.
notice
(
"total %d cases executed"
%
(
runNum
))
continue
tdLog
.
notice
(
"total %d Cluster test case(s) executed"
%
(
runNum
))
tdCases
=
TDCases
()
tests/pytest/util/dnodes.py
浏览文件 @
3d843d32
...
...
@@ -30,9 +30,6 @@ class TDSimClient:
if
os
.
system
(
cmd
)
!=
0
:
tdLog
.
exit
(
cmd
)
def
setValgrind
(
self
,
value
):
self
.
valgrind
=
value
def
deploy
(
self
):
self
.
logDir
=
"%s/sim/psim/log"
%
(
self
.
path
,)
self
.
cfgDir
=
"%s/sim/psim/cfg"
%
(
self
.
path
)
...
...
@@ -82,11 +79,15 @@ class TDDnode:
self
.
index
=
index
self
.
running
=
0
self
.
deployed
=
0
self
.
testCluster
=
False
self
.
valgrind
=
0
def
init
(
self
,
path
):
self
.
path
=
path
def
setTestCluster
(
self
,
value
):
self
.
testCluster
=
value
def
setValgrind
(
self
,
value
):
self
.
valgrind
=
value
...
...
@@ -124,7 +125,9 @@ class TDDnode:
if
os
.
system
(
cmd
)
!=
0
:
tdLog
.
exit
(
cmd
)
self
.
startIP
()
if
self
.
testCluster
:
self
.
startIP
()
self
.
cfg
(
"masterIp"
,
"192.168.0.1"
)
self
.
cfg
(
"secondIp"
,
"192.168.0.2"
)
self
.
cfg
(
"publicIp"
,
"192.168.0.%d"
%
(
self
.
index
))
...
...
@@ -292,11 +295,15 @@ class TDDnodes:
self
.
sim
.
init
(
self
.
path
)
self
.
sim
.
deploy
()
def
setTestCluster
(
self
,
value
):
self
.
testCluster
=
value
def
setValgrind
(
self
,
value
):
self
.
valgrind
=
value
def
deploy
(
self
,
index
):
self
.
check
(
index
)
self
.
dnodes
[
index
-
1
].
setTestCluster
(
self
.
testCluster
)
self
.
dnodes
[
index
-
1
].
setValgrind
(
self
.
valgrind
)
self
.
dnodes
[
index
-
1
].
deploy
()
...
...
@@ -318,11 +325,15 @@ class TDDnodes:
def
startIP
(
self
,
index
):
self
.
check
(
index
)
self
.
dnodes
[
index
-
1
].
startIP
()
if
self
.
testCluster
:
self
.
dnodes
[
index
-
1
].
startIP
()
def
stopIP
(
self
,
index
):
self
.
check
(
index
)
self
.
dnodes
[
index
-
1
].
stopIP
()
if
self
.
dnodes
[
index
-
1
].
testCluster
:
self
.
dnodes
[
index
-
1
].
stopIP
()
def
check
(
self
,
index
):
if
index
<
1
or
index
>
10
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录