fix(接口测试): 修复脚本终止测试命令导致报告无法停止异常

This commit is contained in:
fit2-zhao 2022-02-23 17:15:59 +08:00 committed by fit2-zhao
parent 20a70886e2
commit 004eeee671
3 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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) {