Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
2c8502f7
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 3 年多
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c8502f7
编写于
4月 23, 2021
作者:
F
fit2-zhao
提交者:
fit2-zhao
4月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(接口自动化): 并发数量控制
上级
060be4f6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
16 deletion
+47
-16
backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java
...java/io/metersphere/api/service/ApiAutomationService.java
+28
-12
backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java
...java/io/metersphere/api/service/ApiDefinitionService.java
+13
-1
frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue
...nts/track/plan/view/comonents/api/TestPlanApiCaseList.vue
+2
-1
frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue
...track/plan/view/comonents/api/TestPlanApiScenarioList.vue
+4
-2
未找到文件。
backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java
浏览文件 @
2c8502f7
...
...
@@ -48,6 +48,7 @@ import org.apache.ibatis.session.SqlSession;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.jorphan.collections.HashTree
;
import
org.apache.jorphan.collections.ListedHashTree
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -594,7 +595,6 @@ public class ApiAutomationService {
report
.
setProjectId
(
projectId
);
report
.
setScenarioName
(
scenarioName
);
report
.
setScenarioId
(
scenarioId
);
apiScenarioReportMapper
.
insert
(
report
);
return
report
;
}
...
...
@@ -696,7 +696,7 @@ public class ApiAutomationService {
* @param request
* @return
*/
public
String
abandoned
Run
(
RunScenarioRequest
request
)
{
public
String
parallel
Run
(
RunScenarioRequest
request
)
{
ServiceUtils
.
getSelectAllIds
(
request
,
request
.
getCondition
(),
(
query
)
->
extApiScenarioMapper
.
selectIdsByQuery
((
ApiScenarioRequest
)
query
));
...
...
@@ -823,6 +823,7 @@ public class ApiAutomationService {
// 创建场景报告
if
(
reportIds
!=
null
)
{
//如果是测试计划页面触发的执行方式,生成报告时createScenarioReport第二个参数需要特殊处理
APIScenarioReportResult
report
=
null
;
if
(
StringUtils
.
equals
(
request
.
getRunMode
(),
ApiRunMode
.
SCENARIO_PLAN
.
name
()))
{
String
testPlanScenarioId
=
item
.
getId
();
if
(
request
.
getScenarioTestPlanIdMap
()
!=
null
&&
request
.
getScenarioTestPlanIdMap
().
containsKey
(
item
.
getId
()))
{
...
...
@@ -834,12 +835,13 @@ public class ApiAutomationService {
scenario
.
setEnvironmentMap
(
JSON
.
parseObject
(
environment
,
Map
.
class
));
}
}
createScenarioReport
(
group
.
getName
(),
testPlanScenarioId
,
item
.
getName
(),
request
.
getTriggerMode
()
==
null
?
ReportTriggerMode
.
MANUAL
.
name
()
:
request
.
getTriggerMode
(),
report
=
createScenarioReport
(
group
.
getName
(),
testPlanScenarioId
,
item
.
getName
(),
request
.
getTriggerMode
()
==
null
?
ReportTriggerMode
.
MANUAL
.
name
()
:
request
.
getTriggerMode
(),
request
.
getExecuteType
(),
item
.
getProjectId
(),
request
.
getReportUserID
(),
request
.
getConfig
());
}
else
{
createScenarioReport
(
group
.
getName
(),
item
.
getId
(),
item
.
getName
(),
request
.
getTriggerMode
()
==
null
?
ReportTriggerMode
.
MANUAL
.
name
()
:
request
.
getTriggerMode
(),
report
=
createScenarioReport
(
group
.
getName
(),
item
.
getId
(),
item
.
getName
(),
request
.
getTriggerMode
()
==
null
?
ReportTriggerMode
.
MANUAL
.
name
()
:
request
.
getTriggerMode
(),
request
.
getExecuteType
(),
item
.
getProjectId
(),
request
.
getReportUserID
(),
request
.
getConfig
());
}
apiScenarioReportMapper
.
insert
(
report
);
reportIds
.
add
(
group
.
getName
());
}
group
.
setHashTree
(
scenarios
);
...
...
@@ -909,7 +911,7 @@ public class ApiAutomationService {
* @param request
* @return
*/
public
String
r
un
(
RunScenarioRequest
request
)
{
public
String
serialR
un
(
RunScenarioRequest
request
)
{
ServiceUtils
.
getSelectAllIds
(
request
,
request
.
getCondition
(),
(
query
)
->
extApiScenarioMapper
.
selectIdsByQuery
((
ApiScenarioRequest
)
query
));
List
<
String
>
ids
=
request
.
getIds
();
...
...
@@ -953,6 +955,25 @@ public class ApiAutomationService {
return
request
.
getId
();
}
@Value
(
"${run.concurrency}"
)
private
String
concurrency
;
public
String
run
(
RunScenarioRequest
request
)
{
if
(
request
.
getConfig
()
!=
null
&&
request
.
getConfig
().
getMode
().
equals
(
"serial"
))
{
return
this
.
serialRun
(
request
);
}
else
{
// 校验并发数量
int
count
=
50
;
if
(
StringUtils
.
isNotEmpty
(
concurrency
))
{
count
=
Integer
.
parseInt
(
concurrency
);
}
if
(
request
.
getIds
().
size
()
>
count
)
{
MSException
.
throwException
(
"并发数量过大,请重新选择!"
);
}
return
this
.
parallelRun
(
request
);
}
}
public
void
checkScenarioIsRunning
(
List
<
String
>
ids
)
{
List
<
ApiScenarioReport
>
lastReportStatusByIds
=
apiReportService
.
selectLastReportByIds
(
ids
);
for
(
ApiScenarioReport
report
:
lastReportStatusByIds
)
{
...
...
@@ -1013,8 +1034,9 @@ public class ApiAutomationService {
MSException
.
throwException
(
e
.
getMessage
());
}
// 调用执行方法
createScenarioReport
(
request
.
getId
(),
request
.
getScenarioId
(),
request
.
getScenarioName
(),
ReportTriggerMode
.
MANUAL
.
name
(),
request
.
getExecuteType
(),
request
.
getProjectId
(),
APIScenarioReportResult
report
=
createScenarioReport
(
request
.
getId
(),
request
.
getScenarioId
(),
request
.
getScenarioName
(),
ReportTriggerMode
.
MANUAL
.
name
(),
request
.
getExecuteType
(),
request
.
getProjectId
(),
SessionUtils
.
getUserId
(),
null
);
apiScenarioReportMapper
.
insert
(
report
);
// 调用执行方法
// jMeterService.runTest(request.getId(), hashTree, ApiRunMode.SCENARIO.name(), true, null);
// 调用执行方法
...
...
@@ -1037,11 +1059,6 @@ public class ApiAutomationService {
if
(
CollectionUtils
.
isEmpty
(
request
.
getPlanIds
()))
{
MSException
.
throwException
(
Translator
.
get
(
"plan id is null "
));
}
// List<String> scenarioIds = request.getScenarioIds();
// if (request.isSelectAllDate()) {
// scenarioIds = this.getAllScenarioIdsByFontedSelect(
// request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
// }
Map
<
String
,
List
<
String
>>
mapping
=
request
.
getMapping
();
Map
<
String
,
String
>
envMap
=
request
.
getEnvMap
();
Set
<
String
>
set
=
mapping
.
keySet
();
...
...
@@ -1158,7 +1175,6 @@ public class ApiAutomationService {
testCaseReviewScenario
.
setUpdateTime
(
System
.
currentTimeMillis
());
testCaseReviewScenario
.
setEnvironment
(
JSON
.
toJSONString
(
newEnvMap
));
testCaseReviewScenarioMapper
.
insert
(
testCaseReviewScenario
);
});
}
...
...
backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java
浏览文件 @
2c8502f7
...
...
@@ -43,6 +43,7 @@ import org.apache.ibatis.session.SqlSession;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.jorphan.collections.HashTree
;
import
org.aspectj.util.FileUtil
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -293,7 +294,8 @@ public class ApiDefinitionService {
test
.
setTags
(
request
.
getTags
());
}
else
{
test
.
setTags
(
null
);
}
this
.
setModule
(
test
);
}
this
.
setModule
(
test
);
apiDefinitionMapper
.
updateByPrimaryKeySelective
(
test
);
return
test
;
}
...
...
@@ -526,6 +528,9 @@ public class ApiDefinitionService {
}
}
@Value
(
"${run.concurrency}"
)
private
String
concurrency
;
/**
* 测试执行
*
...
...
@@ -534,6 +539,13 @@ public class ApiDefinitionService {
* @return
*/
public
String
run
(
RunDefinitionRequest
request
,
List
<
MultipartFile
>
bodyFiles
)
{
int
count
=
100
;
if
(
StringUtils
.
isNotEmpty
(
concurrency
))
{
count
=
Integer
.
parseInt
(
concurrency
);
}
if
(
request
.
getTestElement
()
!=
null
&&
request
.
getTestElement
().
getHashTree
().
size
()
==
1
&&
request
.
getTestElement
().
getHashTree
().
get
(
0
).
getHashTree
().
size
()
>
count
)
{
MSException
.
throwException
(
"并发数量过大,请重新选择!"
);
}
List
<
String
>
bodyUploadIds
=
new
ArrayList
<>(
request
.
getBodyUploadIds
());
FileUtils
.
createBodyFiles
(
bodyUploadIds
,
bodyFiles
);
...
...
frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue
浏览文件 @
2c8502f7
...
...
@@ -605,6 +605,7 @@ export default {
let
reqObj
=
{
id
:
getUUID
().
substring
(
0
,
8
),
testElement
:
testPlan
,
type
:
'
API_PLAN
'
,
reportId
:
"
run
"
,
projectId
:
projectId
};
let
bodyFiles
=
getBodyUploadFiles
(
reqObj
,
this
.
runData
);
this
.
$fileUpload
(
"
/api/definition/run
"
,
null
,
bodyFiles
,
reqObj
,
response
=>
{
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
});
}
else
{
testPlan
.
serializeThreadgroups
=
false
;
...
...
@@ -617,10 +618,10 @@ export default {
let
reqObj
=
{
id
:
getUUID
().
substring
(
0
,
8
),
testElement
:
testPlan
,
type
:
'
API_PLAN
'
,
reportId
:
"
run
"
,
projectId
:
projectId
};
let
bodyFiles
=
getBodyUploadFiles
(
reqObj
,
this
.
runData
);
this
.
$fileUpload
(
"
/api/definition/run
"
,
null
,
bodyFiles
,
reqObj
,
response
=>
{
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
});
}
this
.
search
();
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
},
autoCheckStatus
()
{
// 检查执行结果,自动更新计划状态
if
(
!
this
.
planId
)
{
...
...
frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue
浏览文件 @
2c8502f7
...
...
@@ -324,7 +324,9 @@ export default {
this
.
selectRows
.
forEach
(
row
=>
{
this
.
buildExecuteParam
(
param
,
row
);
});
this
.
$post
(
"
/test/case/review/scenario/case/run
"
,
param
,
response
=>
{});
this
.
$post
(
"
/test/case/review/scenario/case/run
"
,
param
,
response
=>
{
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
});
}
if
(
this
.
planId
)
{
let
selectParam
=
buildBatchParam
(
this
);
...
...
@@ -334,9 +336,9 @@ export default {
});
param
.
condition
=
selectParam
.
condition
;
this
.
$post
(
"
/test/plan/scenario/case/run
"
,
param
,
response
=>
{
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
});
}
this
.
$message
(
'
任务执行中,请稍后刷新查看结果
'
);
this
.
search
();
},
execute
(
row
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录