fix(接口定义/测试跟踪) 优化接口定义批量执行;修复性能测试批量执行触发状态问题

--bug=1006802 --user=赵勇 【任务中心】测试计划,批量串行执行性能测试,执行完成点击任务中心,提示报告不存在 https://www.tapd.cn/55049933/s/1052563
This commit is contained in:
fit2-zhao 2021-09-27 18:03:36 +08:00 committed by fit2-zhao
parent 0c692cd794
commit e459e87039
8 changed files with 58 additions and 31 deletions

View File

@ -1,5 +1,7 @@
package io.metersphere.api.dto.definition;
import io.metersphere.base.domain.ApiDefinitionExecResult;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import lombok.Getter;
import lombok.Setter;
@ -16,4 +18,8 @@ public class RunCaseRequest {
private String environmentId;
private String testPlanId;
private ApiTestCaseWithBLOBs bloBs;
private ApiDefinitionExecResult report;
}

View File

@ -279,6 +279,14 @@ public class ElementUtil {
element.fluentPut("tcpPreProcessor", tcpPreProcessor);
}
}
} else if (element != null && element.getString("type").equals("HTTPSamplerProxy")) {
if (element.getString("authManager") != null) {
JSONObject authManager = JSON.parseObject(element.getString("authManager"));
if (authManager != null && authManager.get("clazzName") == null) {
authManager.fluentPut("clazzName", clazzMap.get(authManager.getString("type")));
element.fluentPut("authManager", authManager);
}
}
}
if (element != null && element.get("clazzName") == null && clazzMap.containsKey(element.getString("type"))) {
element.fluentPut("clazzName", clazzMap.get(element.getString("type")));

View File

@ -703,50 +703,53 @@ public class ApiTestCaseService {
public void batchRun(ApiCaseBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiTestCaseMapper.selectIdsByQuery((ApiTestCaseRequest) query));
Map<String, ApiDefinitionExecResult> executeQueue = new HashMap<>();
List<RunCaseRequest> executeQueue = new LinkedList<>();
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiDefinitionExecResultMapper batchMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
for (String testCaseId : request.getIds()) {
ApiDefinitionExecResult report = addResult(testCaseId, APITestStatus.Running.name());
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testCaseId);
if (caseWithBLOBs != null) {
report.setName(caseWithBLOBs.getName());
caseWithBLOBs.setLastResultId(report.getId());
caseWithBLOBs.setUpdateTime(System.currentTimeMillis());
caseWithBLOBs.setStatus(APITestStatus.Running.name());
apiTestCaseMapper.updateByPrimaryKey(caseWithBLOBs);
}
batchMapper.insert(report);
executeQueue.put(testCaseId, report);
}
sqlSession.flushStatements();
for (String caseId : executeQueue.keySet()) {
ApiTestCaseExample example = new ApiTestCaseExample();
example.createCriteria().andIdIn(request.getIds());
List<ApiTestCaseWithBLOBs> list = apiTestCaseMapper.selectByExampleWithBLOBs(example);
ApiTestCaseMapper sqlSessionMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
for (ApiTestCaseWithBLOBs caseWithBLOBs : list) {
ApiDefinitionExecResult report = addResult(caseWithBLOBs.getId(), APITestStatus.Running.name());
report.setName(caseWithBLOBs.getName());
caseWithBLOBs.setLastResultId(report.getId());
caseWithBLOBs.setUpdateTime(System.currentTimeMillis());
caseWithBLOBs.setStatus(APITestStatus.Running.name());
sqlSessionMapper.updateByPrimaryKey(caseWithBLOBs);
// 执行对象
RunCaseRequest runCaseRequest = new RunCaseRequest();
runCaseRequest.setRunMode(ApiRunMode.DEFINITION.name());
runCaseRequest.setCaseId(caseId);
runCaseRequest.setReportId(executeQueue.get(caseId).getId());
runCaseRequest.setCaseId(caseWithBLOBs.getId());
runCaseRequest.setReportId(report.getId());
runCaseRequest.setEnvironmentId(request.getEnvironmentId());
runCaseRequest.setBloBs(caseWithBLOBs);
runCaseRequest.setReport(report);
batchMapper.insert(report);
executeQueue.add(runCaseRequest);
}
sqlSession.flushStatements();
for (RunCaseRequest runCaseRequest : executeQueue) {
run(runCaseRequest);
MessageCache.batchTestCases.put(executeQueue.get(caseId).getId(), executeQueue.get(caseId));
MessageCache.batchTestCases.put(runCaseRequest.getReportId(), runCaseRequest.getReport());
}
}
public String run(RunCaseRequest request) {
ApiTestCaseWithBLOBs testCaseWithBLOBs = null;
ApiTestCaseWithBLOBs testCaseWithBLOBs = request.getBloBs();
if (StringUtils.equals(request.getRunMode(), ApiRunMode.JENKINS_API_PLAN.name())) {
testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getReportId());
request.setCaseId(request.getReportId());
} else {
testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId());
//通过测试计划id查询环境
request.setReportId(request.getTestPlanId());
}
if (StringUtils.equals(request.getRunMode(), ApiRunMode.JENKINS.name())) {
request.setReportId(request.getEnvironmentId());
}
if (StringUtils.equals(request.getRunMode(), ApiRunMode.JENKINS_API_PLAN.name())) {
//通过测试计划id查询环境
request.setReportId(request.getTestPlanId());
}
// 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取
if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) {
try {

View File

@ -559,6 +559,9 @@
#{nodeId}
</foreach>
</if>
<if test="request.protocol != null and request.protocol !=''">
and a.protocol = #{request.protocol}
</if>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
@ -571,7 +574,7 @@
<select id="selectIdsByQuery" resultType="java.lang.String">
SELECT t1.id
FROM api_test_case t1
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
<if test="(request.moduleIds != null and request.moduleIds.size() > 0 ) or (request.protocol!=null and request.protocol!='' )">
inner join api_definition a on t1.api_definition_id = a.id
</if>
<include refid="queryWhereCondition"/>

View File

@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.TestPlanLoadCase;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.TriggerMode;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.ResetOrderRequest;
@ -66,6 +67,11 @@ public class TestPlanLoadCaseController {
@PostMapping("/run/batch")
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.EXECUTE, content = "#msClass.getRunLogDetails(#request.requests)", msClass = TestPlanLoadCaseService.class)
public void runBatch(@RequestBody RunBatchTestPlanRequest request) {
if (request.getRequests() != null) {
for (RunTestPlanRequest req : request.getRequests()) {
req.setTriggerMode(TriggerMode.BATCH.name());
}
}
testPlanLoadCaseService.runBatch(request);
}
@ -81,13 +87,13 @@ public class TestPlanLoadCaseController {
}
@PostMapping("/update")
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#testPlanLoadCase.id)", msClass = TestPlanLoadCaseService.class)
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#testPlanLoadCase.id)", msClass = TestPlanLoadCaseService.class)
public void update(@RequestBody TestPlanLoadCase testPlanLoadCase) {
testPlanLoadCaseService.update(testPlanLoadCase);
}
@PostMapping("/update/api")
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#testPlanLoadCase.id)", msClass = TestPlanLoadCaseService.class)
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#testPlanLoadCase.id)", msClass = TestPlanLoadCaseService.class)
public void updateByApi(@RequestBody TestPlanLoadCase testPlanLoadCase) {
testPlanLoadCaseService.updateByApi(testPlanLoadCase);
}

View File

@ -36,6 +36,7 @@ export default {
},
save() {
this.$emit('batchRun', this.environment);
this.close();
}
}
}

View File

@ -517,7 +517,7 @@ export default {
obj.ids = Array.from(this.selectRows).map(row => row.id);
obj.environmentId = environment.id;
obj.condition = this.condition;
obj.condition.status = "";
this.$post('/api/testcase/batch/run', obj, () => {
this.condition.ids = [];
this.$refs.batchRun.close();

View File

@ -267,7 +267,7 @@ export default {
testPlanLoadId: loadCase.id,
userId: getCurrentUserId(),
projectId: getCurrentProjectID(),
triggerMode: 'MANUAL'
triggerMode: 'BATCH'
});
});
let obj = {config: config, requests: runArr, userId: getCurrentUser().id};