diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 6cbc4fe29a..0780785cb7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -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(); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 9fb99478ad..258886a032 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -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 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()) { diff --git a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java index f8330260ee..852093f057 100644 --- a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java +++ b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java @@ -52,7 +52,7 @@ public class SerialScenarioExecTask implements Callable { }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());