diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 96109e3c82..505adf184b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -135,7 +135,7 @@ public class ApiDefinitionService { if (StringUtils.isNotBlank(request.getProjectId())) { buildProjectInfo(resList, request.getProjectId()); calculateResult(resList, request.getProjectId()); - }else{ + } else { buildProjectInfoWidthoutProject(resList); } return resList; @@ -1083,6 +1083,7 @@ public class ApiDefinitionService { return null; } APIReportResult reportResult = new APIReportResult(); + reportResult.setStatus(result.getStatus()); reportResult.setContent(result.getContent()); return reportResult; } diff --git a/backend/src/main/java/io/metersphere/api/service/TestResultService.java b/backend/src/main/java/io/metersphere/api/service/TestResultService.java index c48ec5be41..0ff67a6996 100644 --- a/backend/src/main/java/io/metersphere/api/service/TestResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/TestResultService.java @@ -3,8 +3,10 @@ package io.metersphere.api.service; import io.metersphere.api.dto.automation.ApiTestReportVariable; import io.metersphere.api.jmeter.ExecutedHandleSingleton; import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioReportMapper; +import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.ReportTriggerMode; @@ -53,6 +55,8 @@ public class TestResultService { private ApiTestCaseService apiTestCaseService; @Resource private ApiScenarioReportMapper apiScenarioReportMapper; + @Resource + private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; public void saveResults(ResultDTO dto) { // 处理环境 @@ -76,6 +80,7 @@ public class TestResultService { updateTestCaseStates(requestResults, dto.getRunMode()); } + public void editReportTime(ResultDTO dto) { ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(dto.getReportId()); if (report != null) { @@ -120,6 +125,14 @@ public class TestResultService { } } } + } else if (StringUtils.equals(dto.getRunMode(), ApiRunMode.DEFINITION.name())) { + ApiDefinitionExecResult record = new ApiDefinitionExecResult(); + record.setId(dto.getReportId()); + record.setStatus("STOP"); + + ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample(); + example.createCriteria().andIdEqualTo(dto.getReportId()).andStatusEqualTo(APITestStatus.Running.name()); + apiDefinitionExecResultMapper.updateByExampleSelective(record, example); } } diff --git a/backend/src/main/java/io/metersphere/websocket/ApiReportWebSocket.java b/backend/src/main/java/io/metersphere/websocket/ApiReportWebSocket.java index 1d3a61ab99..9ed251b405 100644 --- a/backend/src/main/java/io/metersphere/websocket/ApiReportWebSocket.java +++ b/backend/src/main/java/io/metersphere/websocket/ApiReportWebSocket.java @@ -2,6 +2,7 @@ package io.metersphere.websocket; import io.metersphere.api.dto.APIReportResult; import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.utils.LogUtil; import lombok.SneakyThrows; import org.apache.commons.lang.StringUtils; @@ -97,8 +98,9 @@ public class ApiReportWebSocket { if (!session.isOpen()) { return; } - if (report != null && StringUtils.isNotEmpty(report.getContent())) { - session.getBasicRemote().sendText(report.getContent()); + if (report != null && StringUtils.isNotEmpty(report.getStatus()) && + !StringUtils.equals(report.getStatus(), APITestStatus.Running.name())) { + session.getBasicRemote().sendText(StringUtils.isNotEmpty(report.getContent()) ? report.getContent() : "{}"); session.close(); } } catch (Exception e) {