Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
3c794173
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看板
提交
3c794173
编写于
5月 29, 2020
作者:
S
Shuduo Sang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add multi-threading test case
[TD-450]
上级
04e86597
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
215 addition
and
0 deletion
+215
-0
tests/pytest/random-test/random-test-multi-threading.py
tests/pytest/random-test/random-test-multi-threading.py
+215
-0
未找到文件。
tests/pytest/random-test/random-test-multi-threading.py
0 → 100644
浏览文件 @
3c794173
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
random
import
threading
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
current_tb
=
""
last_tb
=
""
written
=
0
class
Test
(
threading
.
Thread
):
def
__init__
(
self
,
threadId
,
name
,
sleepTime
):
threading
.
Thread
.
__init__
(
self
)
self
.
threadId
=
threadId
self
.
name
=
name
self
.
sleepTime
=
sleepTime
self
.
threadLock
=
threading
.
Lock
()
def
create_table
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"create a table"
)
current_tb
=
"tb%d"
%
int
(
round
(
time
.
time
()
*
1000
))
tdLog
.
info
(
"current table %s"
%
current_tb
)
if
(
current_tb
==
last_tb
):
return
else
:
tdSql
.
execute
(
'create table %s (ts timestamp, speed int)'
%
current_tb
)
last_tb
=
current_tb
written
=
0
def
insert_data
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"will insert data to table"
)
if
(
current_tb
==
""
):
tdLog
.
info
(
"no table, create first"
)
self
.
create_table
()
tdLog
.
info
(
"insert data to table"
)
for
i
in
range
(
0
,
10
):
self
.
threadLock
.
acquire
()
insertRows
=
1000
tdLog
.
info
(
"insert %d rows to %s"
%
(
insertRows
,
current_tb
))
for
j
in
range
(
0
,
insertRows
):
ret
=
tdSql
.
execute
(
'insert into %s values (now + %dm, %d)'
%
(
current_tb
,
j
,
j
))
written
=
written
+
1
self
.
threadLock
.
release
()
def
query_data
(
self
):
global
current_tb
global
last_tb
global
written
if
(
written
>
0
):
tdLog
.
info
(
"query data from table"
)
tdSql
.
query
(
"select * from %s"
%
last_tb
)
tdSql
.
checkRows
(
written
)
def
create_stable
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"create a super table"
)
def
restart_database
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"restart databae"
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
tdLog
.
sleep
(
5
)
def
force_restart
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"force restart database"
)
tdDnodes
.
forcestop
(
1
)
tdDnodes
.
start
(
1
)
tdLog
.
sleep
(
5
)
def
drop_table
(
self
):
global
current_tb
global
last_tb
global
written
for
i
in
range
(
0
,
10
):
self
.
threadLock
.
acquire
()
tdLog
.
info
(
"current_tb %s"
%
current_tb
)
if
(
current_tb
!=
""
):
tdLog
.
info
(
"drop current tb %s"
%
current_tb
)
tdSql
.
execute
(
"drop table %s"
%
current_tb
)
current_tb
=
""
last_tb
=
""
written
=
0
tdLog
.
sleep
(
self
.
sleepTime
)
self
.
threadLock
.
release
()
def
reset_query_cache
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"reset query cache"
)
tdSql
.
execute
(
"reset query cache"
)
tdLog
.
sleep
(
1
)
def
reset_database
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"reset database"
)
tdDnodes
.
forcestop
(
1
)
tdDnodes
.
deploy
(
1
)
current_tb
=
""
last_tb
=
""
written
=
0
tdDnodes
.
start
(
1
)
tdSql
.
prepare
()
def
delete_datafiles
(
self
):
global
current_tb
global
last_tb
global
written
tdLog
.
info
(
"delete data files"
)
dnodesDir
=
tdDnodes
.
getDnodesRootDir
()
dataDir
=
dnodesDir
+
'/dnode1/*'
deleteCmd
=
'rm -rf %s'
%
dataDir
os
.
system
(
deleteCmd
)
current_tb
=
""
last_tb
=
""
written
=
0
tdDnodes
.
start
(
1
)
tdSql
.
prepare
()
def
run
(
self
):
switch
=
{
1
:
self
.
create_table
,
2
:
self
.
insert_data
,
3
:
self
.
query_data
,
4
:
self
.
create_stable
,
5
:
self
.
restart_database
,
6
:
self
.
force_restart
,
7
:
self
.
drop_table
,
8
:
self
.
reset_query_cache
,
9
:
self
.
reset_database
,
10
:
self
.
delete_datafiles
,
}
switch
.
get
(
self
.
threadId
,
lambda
:
"ERROR"
)()
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
run
(
self
):
tdSql
.
prepare
()
test1
=
Test
(
2
,
"insert_data"
,
1
)
test2
=
Test
(
7
,
"drop_table"
,
2
)
test1
.
start
()
test2
.
start
()
test1
.
join
()
test2
.
join
()
tdLog
.
info
(
"end of test"
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录