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

View File

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

View File

@ -559,6 +559,9 @@
#{nodeId} #{nodeId}
</foreach> </foreach>
</if> </if>
<if test="request.protocol != null and request.protocol !=''">
and a.protocol = #{request.protocol}
</if>
<if test="request.combine != null"> <if test="request.combine != null">
<include refid="combine"> <include refid="combine">
<property name="condition" value="request.combine"/> <property name="condition" value="request.combine"/>
@ -571,7 +574,7 @@
<select id="selectIdsByQuery" resultType="java.lang.String"> <select id="selectIdsByQuery" resultType="java.lang.String">
SELECT t1.id SELECT t1.id
FROM api_test_case t1 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 inner join api_definition a on t1.api_definition_id = a.id
</if> </if>
<include refid="queryWhereCondition"/> <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.LoadTest;
import io.metersphere.base.domain.TestPlanLoadCase; import io.metersphere.base.domain.TestPlanLoadCase;
import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.TriggerMode;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.ResetOrderRequest; import io.metersphere.controller.request.ResetOrderRequest;
@ -66,6 +67,11 @@ public class TestPlanLoadCaseController {
@PostMapping("/run/batch") @PostMapping("/run/batch")
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.EXECUTE, content = "#msClass.getRunLogDetails(#request.requests)", msClass = TestPlanLoadCaseService.class) @MsAuditLog(module = "track_test_plan", type = OperLogConstants.EXECUTE, content = "#msClass.getRunLogDetails(#request.requests)", msClass = TestPlanLoadCaseService.class)
public void runBatch(@RequestBody RunBatchTestPlanRequest request) { public void runBatch(@RequestBody RunBatchTestPlanRequest request) {
if (request.getRequests() != null) {
for (RunTestPlanRequest req : request.getRequests()) {
req.setTriggerMode(TriggerMode.BATCH.name());
}
}
testPlanLoadCaseService.runBatch(request); testPlanLoadCaseService.runBatch(request);
} }

View File

@ -36,6 +36,7 @@ export default {
}, },
save() { save() {
this.$emit('batchRun', this.environment); 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.ids = Array.from(this.selectRows).map(row => row.id);
obj.environmentId = environment.id; obj.environmentId = environment.id;
obj.condition = this.condition; obj.condition = this.condition;
obj.condition.status = "";
this.$post('/api/testcase/batch/run', obj, () => { this.$post('/api/testcase/batch/run', obj, () => {
this.condition.ids = []; this.condition.ids = [];
this.$refs.batchRun.close(); this.$refs.batchRun.close();

View File

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