fix(测试计划): 修复测试计划获取没有步骤结果场景时不会处理报告记录的问题

修复测试计划获取没有步骤结果场景时不会处理报告记录的问题
This commit is contained in:
song-tianyang 2021-12-18 02:40:21 +08:00 committed by song-tianyang
parent b7cd21bc4a
commit 75e678fc87
3 changed files with 32 additions and 4 deletions

View File

@ -1481,7 +1481,7 @@ public class ApiAutomationService {
String testId = executeQueue.get(reportId).getTestId();
if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(executeQueue.get(reportId).getTestId())) {
testPlanScenarioId = executeQueue.get(reportId).getTestId();
testId = request.getScenarioTestPlanIdMap().get(executeQueue.get(reportId).getTestId());
testId = reportId;
} else {
testPlanScenarioId = request.getPlanScenarioId();
}

View File

@ -292,14 +292,13 @@ public class ApiScenarioReportService {
scenario.setExecuteTimes(executeTimes + 1);
apiScenarioMapper.updateByPrimaryKey(scenario);
// 发送通知
// sendNotice(scenario);
}
}
returnReport = report;
reportIds.add(report.getId());
MessageCache.executionQueue.remove(report.getId());
}
counterPlanScenarioReport(result);
return returnReport;
}
@ -426,6 +425,8 @@ public class ApiScenarioReportService {
LogUtil.error("未获取到场景报告。 报告ID" + scenarioResult.getName() + "。 步骤信息:" + JSON.toJSONString(scenarioResult));
}
}
// 针对未正常返回结果的报告计数
counterPlanScenarioReport(result);
testPlanLog.info("TestPlanReportId" + JSONArray.toJSONString(testPlanReportIdList) + " EXECUTE OVER. SCENARIO STATUS : " + JSONObject.toJSONString(scenarioAndErrorMap));
for (String reportId : testPlanReportIdList) {
TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(reportId, null, scenarioAndErrorMap, null);
@ -577,6 +578,33 @@ public class ApiScenarioReportService {
}
}
private void counterPlanScenarioReport(TestResult result) {
if (CollectionUtils.isEmpty(result.getScenarios()) && StringUtils.isNotEmpty(result.getTestId())) {
List<String> list = new LinkedList<>();
try {
list = JSON.parseObject(result.getTestId(), List.class);
} catch (Exception e) {
list.add(result.getTestId());
}
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(result.getTestId());
if (report != null) {
report.setStatus("Error");
apiScenarioReportMapper.updateByPrimaryKey(report);
MessageCache.scenarioExecResourceLock.remove(report.getId());
MessageCache.executionQueue.remove(report.getId());
if (StringUtils.equals(report.getExecuteType(), ExecuteType.Marge.name()) || StringUtils.equals(report.getScenarioId(), result.getSetReportId())) {
Object obj = MessageCache.cache.get(result.getSetReportId());
if (obj != null) {
ReportCounter counter = (ReportCounter) obj;
counter.getCompletedIds().add(report.getId());
MessageCache.cache.put(result.getSetReportId(), counter);
}
}
}
}
}
public ApiScenarioReport updateScenario(TestResult result) {
ApiScenarioReport lastReport = null;
for (ScenarioResult item : result.getScenarios()) {

View File

@ -52,7 +52,7 @@ public class SerialScenarioExecTask<T> implements Callable<T> {
}else {
reportId = runModeDataDTO.getTestId();
}
jMeterService.runTest(runModeDataDTO.getTestId(), reportId, request.getRunMode(), testPlanScenarioId, request.getConfig());
jMeterService.runTest(runModeDataDTO.getReport().getId(), reportId, request.getRunMode(), testPlanScenarioId, request.getConfig());
} else {
reportId = runModeDataDTO.getReport().getId();
jMeterService.runLocal(runModeDataDTO.getReport().getId(),request.getConfig(), runModeDataDTO.getHashTree(), TriggerMode.BATCH.name().equals(request.getTriggerMode()) ? TriggerMode.BATCH.name() : request.getReportId(), request.getRunMode());