Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
76721f8a
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
76721f8a
编写于
10月 26, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into enhance/TS-493-M
上级
73003fae
f22c0c07
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
137 addition
and
71 deletion
+137
-71
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+31
-4
tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py
...pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py
+106
-67
未找到文件。
src/kit/taosdemo/taosdemo.c
浏览文件 @
76721f8a
...
...
@@ -3498,12 +3498,20 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
memset
(
response_buf
,
0
,
RESP_BUF_LEN
);
resp_len
=
sizeof
(
response_buf
)
-
1
;
received
=
0
;
char
resEncodingChunk
[]
=
"Encoding: chunked"
;
char
resHttp
[]
=
"HTTP/1.1 "
;
int
resHttpLen
=
strlen
(
resHttp
);
char
resHttpOk
[]
=
"HTTP/1.1 200 OK"
;
int
resHttpOkLen
=
strlen
(
resHttpOk
);
do
{
#ifdef WINDOWS
bytes
=
recv
(
sockfd
,
response_buf
+
received
,
resp_len
-
received
,
0
);
#else
bytes
=
read
(
sockfd
,
response_buf
+
received
,
resp_len
-
received
);
#endif
verbosePrint
(
"%s() LN%d: bytes:%d
\n
"
,
__func__
,
__LINE__
,
bytes
);
if
(
bytes
<
0
)
{
free
(
request_buf
);
ERROR_EXIT
(
"reading response from socket"
);
...
...
@@ -3511,6 +3519,23 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
if
(
bytes
==
0
)
break
;
received
+=
bytes
;
response_buf
[
RESP_BUF_LEN
-
1
]
=
'\0'
;
if
(
strlen
(
response_buf
))
{
verbosePrint
(
"%s() LN%d: received:%d resp_len:%d, response_buf:
\n
%s
\n
"
,
__func__
,
__LINE__
,
received
,
resp_len
,
response_buf
);
if
(((
NULL
==
strstr
(
response_buf
,
resEncodingChunk
))
&&
(
0
==
strncmp
(
response_buf
,
resHttp
,
resHttpLen
)))
||
((
0
==
strncmp
(
response_buf
,
resHttpOk
,
resHttpOkLen
))
&&
(
NULL
!=
strstr
(
response_buf
,
"
\"
status
\"
:"
))))
{
debugPrint
(
"%s() LN%d: received:%d resp_len:%d, response_buf:
\n
%s
\n
"
,
__func__
,
__LINE__
,
received
,
resp_len
,
response_buf
);
break
;
}
}
}
while
(
received
<
resp_len
);
if
(
received
==
resp_len
)
{
...
...
@@ -3518,9 +3543,6 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
ERROR_EXIT
(
"storing complete response from socket"
);
}
response_buf
[
RESP_BUF_LEN
-
1
]
=
'\0'
;
printf
(
"Response:
\n
%s
\n
"
,
response_buf
);
if
(
strlen
(
pThreadInfo
->
filePath
)
>
0
)
{
appendResultBufToFile
(
response_buf
,
pThreadInfo
);
}
...
...
@@ -3533,6 +3555,11 @@ static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port
close
(
sockfd
);
#endif
if
(
NULL
==
strstr
(
response_buf
,
"
\"
status
\"
:
\"
succ
\"
"
))
{
errorPrint
(
"%s() LN%d, Response:
\n
%s
\n
"
,
__func__
,
__LINE__
,
response_buf
);
return
-
1
;
}
return
0
;
}
...
...
@@ -12107,4 +12134,4 @@ int main(int argc, char *argv[]) {
}
return
0
;
}
\ No newline at end of file
}
tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py
浏览文件 @
76721f8a
...
...
@@ -20,14 +20,16 @@ from util.dnodes import *
import
time
from
datetime
import
datetime
import
ast
import
re
# from assertpy import assert_that
import
subprocess
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
...
...
@@ -40,52 +42,54 @@ class TDTestCase:
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
break
return
buildPath
# 获取taosc接口查询的结果文件中的内容,返回每行数据,并断言数据的第一列内容。
def
assertfileDataTaosc
(
self
,
filename
,
expectResult
):
def
assertfileDataTaosc
(
self
,
filename
,
expectResult
):
self
.
filename
=
filename
self
.
expectResult
=
expectResult
with
open
(
"%s"
%
filename
,
'r+'
)
as
f1
:
with
open
(
"%s"
%
filename
,
'r+'
)
as
f1
:
for
line
in
f1
.
readlines
():
queryResult
=
line
.
strip
().
split
()[
0
]
self
.
assertCheck
(
filename
,
queryResult
,
expectResult
)
self
.
assertCheck
(
filename
,
queryResult
,
expectResult
)
# 获取restful接口查询的结果文件中的关键内容,目前的关键内容找到第一个key就跳出循,所以就只有一个数据。后续再修改多个结果文件。
def
getfileDataRestful
(
self
,
filename
):
def
getfileDataRestful
(
self
,
filename
):
self
.
filename
=
filename
with
open
(
"%s"
%
filename
,
'r+'
)
as
f1
:
with
open
(
"%s"
%
filename
,
'r+'
)
as
f1
:
for
line
in
f1
.
readlines
():
contents
=
line
.
strip
()
if
contents
.
find
(
"data"
)
!=
-
1
:
pattern
=
re
.
compile
(
"{.*}"
)
contents
=
pattern
.
search
(
contents
).
group
()
contentsDict
=
ast
.
literal_eval
(
contents
)
# 字符串转换为字典
queryResult
=
contentsDict
[
'data'
][
0
][
0
]
break
return
queryResult
# 获取taosc接口查询次数
def
queryTimesTaosc
(
self
,
filename
):
def
queryTimesTaosc
(
self
,
filename
):
self
.
filename
=
filename
command
=
'cat %s |wc -l'
%
filename
times
=
int
(
subprocess
.
getstatusoutput
(
command
)[
1
])
command
=
'cat %s |wc -l'
%
filename
times
=
int
(
subprocess
.
getstatusoutput
(
command
)[
1
])
return
times
# 获取restful接口查询次数
def
queryTimesRestful
(
self
,
filename
):
def
queryTimesRestful
(
self
,
filename
):
self
.
filename
=
filename
command
=
'cat %s |grep "200 OK" |wc -l'
%
filename
times
=
int
(
subprocess
.
getstatusoutput
(
command
)[
1
])
command
=
'cat %s |grep "200 OK" |wc -l'
%
filename
times
=
int
(
subprocess
.
getstatusoutput
(
command
)[
1
])
return
times
# 定义断言结果是否正确。不正确返回错误结果,正确即通过。
def
assertCheck
(
self
,
filename
,
queryResult
,
expectResult
):
def
assertCheck
(
self
,
filename
,
queryResult
,
expectResult
):
self
.
filename
=
filename
self
.
queryResult
=
queryResult
self
.
expectResult
=
expectResult
args0
=
(
filename
,
queryResult
,
expectResult
)
assert
queryResult
==
expectResult
,
"Queryfile:%s ,result is %s != expect: %s"
%
args0
assert
queryResult
==
expectResult
,
"Queryfile:%s ,result is %s != expect: %s"
%
args0
def
run
(
self
):
buildPath
=
self
.
getBuildPath
()
...
...
@@ -93,109 +97,144 @@ class TDTestCase:
tdLog
.
exit
(
"taosd not found!"
)
else
:
tdLog
.
info
(
"taosd found in %s"
%
buildPath
)
binPath
=
buildPath
+
"/build/bin/"
binPath
=
buildPath
+
"/build/bin/"
# delete useless files
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf ./all_query*"
)
# taosc query: query specified table and query super table
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTaosc.json"
%
binPath
)
# taosc query: query specified table and query super table
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTaosc.json"
%
binPath
)
os
.
system
(
"cat query_res0.txt* > all_query_res0_taosc.txt"
)
os
.
system
(
"cat query_res1.txt* > all_query_res1_taosc.txt"
)
os
.
system
(
"cat query_res2.txt* > all_query_res2_taosc.txt"
)
# correct Times testcases
# correct Times testcases
queryTimes0Taosc
=
self
.
queryTimesTaosc
(
"all_query_res0_taosc.txt"
)
self
.
assertCheck
(
"all_query_res0_taosc.txt"
,
queryTimes0Taosc
,
6
)
self
.
assertCheck
(
"all_query_res0_taosc.txt"
,
queryTimes0Taosc
,
6
)
queryTimes1Taosc
=
self
.
queryTimesTaosc
(
"all_query_res1_taosc.txt"
)
self
.
assertCheck
(
"all_query_res1_taosc.txt"
,
queryTimes1Taosc
,
6
)
self
.
assertCheck
(
"all_query_res1_taosc.txt"
,
queryTimes1Taosc
,
6
)
queryTimes2Taosc
=
self
.
queryTimesTaosc
(
"all_query_res2_taosc.txt"
)
self
.
assertCheck
(
"all_query_res2_taosc.txt"
,
queryTimes2Taosc
,
20
)
self
.
assertCheck
(
"all_query_res2_taosc.txt"
,
queryTimes2Taosc
,
20
)
# correct data testcase
self
.
assertfileDataTaosc
(
"all_query_res0_taosc.txt"
,
"1604160000099"
)
self
.
assertfileDataTaosc
(
"all_query_res1_taosc.txt"
,
"100"
)
self
.
assertfileDataTaosc
(
"all_query_res2_taosc.txt"
,
"1604160000199"
)
self
.
assertfileDataTaosc
(
"all_query_res0_taosc.txt"
,
"1604160000099"
)
self
.
assertfileDataTaosc
(
"all_query_res1_taosc.txt"
,
"100"
)
self
.
assertfileDataTaosc
(
"all_query_res2_taosc.txt"
,
"1604160000199"
)
# delete useless files
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf ./all_query*"
)
# use restful api to query
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertrestdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryRestful.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertrestdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryRestful.json"
%
binPath
)
os
.
system
(
"cat query_res0.txt* > all_query_res0_rest.txt"
)
os
.
system
(
"cat query_res1.txt* > all_query_res1_rest.txt"
)
os
.
system
(
"cat query_res2.txt* > all_query_res2_rest.txt"
)
# correct Times testcases
# correct Times testcases
queryTimes0Restful
=
self
.
queryTimesRestful
(
"all_query_res0_rest.txt"
)
self
.
assertCheck
(
"all_query_res0_rest.txt"
,
queryTimes0Restful
,
6
)
self
.
assertCheck
(
"all_query_res0_rest.txt"
,
queryTimes0Restful
,
6
)
queryTimes1Restful
=
self
.
queryTimesRestful
(
"all_query_res1_rest.txt"
)
self
.
assertCheck
(
"all_query_res1_rest.txt"
,
queryTimes1Restful
,
6
)
self
.
assertCheck
(
"all_query_res1_rest.txt"
,
queryTimes1Restful
,
6
)
queryTimes2Restful
=
self
.
queryTimesRestful
(
"all_query_res2_rest.txt"
)
self
.
assertCheck
(
"all_query_res2_rest.txt"
,
queryTimes2Restful
,
4
)
self
.
assertCheck
(
"all_query_res2_rest.txt"
,
queryTimes2Restful
,
4
)
# correct data testcase
data0
=
self
.
getfileDataRestful
(
"all_query_res0_rest.txt"
)
self
.
assertCheck
(
'all_query_res0_rest.txt'
,
data0
,
"2020-11-01 00:00:00.009"
)
self
.
assertCheck
(
'all_query_res0_rest.txt'
,
data0
,
"2020-11-01 00:00:00.009"
)
data1
=
self
.
getfileDataRestful
(
"all_query_res1_rest.txt"
)
self
.
assertCheck
(
'all_query_res1_rest.txt'
,
data1
,
10
)
self
.
assertCheck
(
'all_query_res1_rest.txt'
,
data1
,
10
)
data2
=
self
.
getfileDataRestful
(
"all_query_res2_rest.txt"
)
self
.
assertCheck
(
'all_query_res2_rest.txt'
,
data2
,
"2020-11-01 00:00:00.004"
)
self
.
assertCheck
(
'all_query_res2_rest.txt'
,
data2
,
"2020-11-01 00:00:00.004"
)
# query times less than or equal to 100
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querySpeciMutisql100.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querySuperMutisql100.json"
%
binPath
)
#query result print QPS
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryQps.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querySpeciMutisql100.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querySuperMutisql100.json"
%
binPath
)
# query result print QPS
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryQps.json"
%
binPath
)
# use illegal or out of range parameters query json file
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
exceptcode
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTimes0.json"
%
binPath
)
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json"
%
binPath
)
exceptcode
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTimes0.json"
%
binPath
)
assert
exceptcode
!=
0
exceptcode0
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTimesless0.json"
%
binPath
)
exceptcode0
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryTimesless0.json"
%
binPath
)
assert
exceptcode0
!=
0
exceptcode1
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrentless0.json"
%
binPath
)
exceptcode1
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrentless0.json"
%
binPath
)
assert
exceptcode1
!=
0
exceptcode2
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrent0.json"
%
binPath
)
exceptcode2
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrent0.json"
%
binPath
)
assert
exceptcode2
!=
0
exceptcode3
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querrThreadsless0.json"
%
binPath
)
exceptcode3
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querrThreadsless0.json"
%
binPath
)
assert
exceptcode3
!=
0
exceptcode4
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querrThreads0.json"
%
binPath
)
exceptcode4
=
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/querrThreads0.json"
%
binPath
)
assert
exceptcode4
!=
0
# delete useless files
os
.
system
(
"rm -rf ./insert_res.txt"
)
os
.
system
(
"rm -rf tools/taosdemoAllTest/*.py.sql"
)
os
.
system
(
"rm -rf ./querySystemInfo*"
)
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf tools/taosdemoAllTest/*.py.sql"
)
os
.
system
(
"rm -rf ./querySystemInfo*"
)
os
.
system
(
"rm -rf ./query_res*"
)
os
.
system
(
"rm -rf ./all_query*"
)
os
.
system
(
"rm -rf ./test_query_res0.txt"
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录