fix(测试跟踪): 优化接口用例执行时因为环境问题一直转圈的缺陷

--bug=1024642 --user=宋天阳 【测试跟踪】测试计划-关联了SQL
协议的接口case,选择的运行环境没有数据源,单独执行时页面卡住,一直转圈
https://www.tapd.cn/55049933/s/1353213
This commit is contained in:
song-tianyang 2023-03-20 19:43:29 +08:00 committed by fit2-zhao
parent 72897f39ab
commit c57a277dea
5 changed files with 19 additions and 19 deletions

View File

@ -26,6 +26,7 @@ import io.metersphere.commons.utils.*;
import io.metersphere.dto.*;
import io.metersphere.environment.service.BaseEnvironmentService;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.RemakeReportService;
import io.metersphere.service.SystemParameterService;
import io.metersphere.service.definition.TcpApiParamService;
import io.metersphere.utils.LoggerUtil;
@ -65,6 +66,8 @@ public class ApiExecuteService {
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private SystemParameterService systemParameterService;
@Resource
private RemakeReportService remakeReportService;
public MsExecResponseDTO jenkinsRun(RunCaseRequest request) {
ApiTestCaseWithBLOBs caseWithBLOBs = null;
@ -101,7 +104,6 @@ public class ApiExecuteService {
caseWithBLOBs.setStatus(ApiReportStatus.RUNNING.name());
apiTestCaseMapper.updateByPrimaryKey(caseWithBLOBs);
request.setReport(report);
if (StringUtils.isEmpty(request.getRunMode())) {
request.setRunMode(ApiRunMode.DEFINITION.name());
}
@ -126,6 +128,7 @@ public class ApiExecuteService {
jMeterService.verifyPool(testCaseWithBLOBs.getProjectId(), runModeConfigDTO);
// 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testCaseWithBLOBs.getId(), StringUtils.isEmpty(request.getReportId()) ? request.getId() : request.getReportId(), request.getRunMode(), null);
if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) {
try {
HashTree jmeterHashTree = this.generateHashTree(request, testCaseWithBLOBs, runModeConfigDTO);
@ -134,7 +137,7 @@ public class ApiExecuteService {
}
// 调用执行方法
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testCaseWithBLOBs.getId(), StringUtils.isEmpty(request.getReportId()) ? request.getId() : request.getReportId(), request.getRunMode(), jmeterHashTree);
runRequest.setHashTree(jmeterHashTree);
if (MapUtils.isNotEmpty(extendedParameters)) {
runRequest.setExtendedParameters(extendedParameters);
}
@ -147,20 +150,7 @@ public class ApiExecuteService {
}
jMeterService.run(runRequest);
} catch (Exception ex) {
ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(request.getReportId());
if (result != null) {
result.setStatus(ApiReportStatus.ERROR.name());
apiDefinitionExecResultMapper.updateByPrimaryKey(result);
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId());
caseWithBLOBs.setStatus(ApiReportStatus.ERROR.name());
apiTestCaseMapper.updateByPrimaryKey(caseWithBLOBs);
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(caseWithBLOBs.getApiDefinitionId());
if (apiDefinitionWithBLOBs.getProtocol().equals("HTTP")) {
apiDefinitionWithBLOBs.setToBeUpdated(true);
apiDefinitionWithBLOBs.setToBeUpdateTime(System.currentTimeMillis());
apiDefinitionMapper.updateByPrimaryKey(apiDefinitionWithBLOBs);
}
}
remakeReportService.testEnded(runRequest, ex.getMessage());
LogUtil.error(ex.getMessage(), ex);
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.api.jmeter.utils.ReportStatusUtil;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ApiScenarioMapper;
import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper;
import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.enums.ApiReportStatus;
@ -55,6 +56,8 @@ public class TestResultService {
@Resource
private ApiTestCaseService apiTestCaseService;
@Resource
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private BaseShareInfoService baseShareInfoService;
@ -284,7 +287,13 @@ public class TestResultService {
result.setContent(JSON.toJSONString(item));
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(result);
if (StringUtils.isNotEmpty(dto.getTestId())) {
if (StringUtils.equals(dto.getRunMode(), ApiRunMode.API_PLAN.name())) {
TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(dto.getTestId());
if (testPlanApiCase != null) {
testPlanApiCase.setStatus(ApiReportStatus.ERROR.name());
testPlanApiCaseMapper.updateByPrimaryKey(testPlanApiCase);
}
} else if (StringUtils.isNotEmpty(dto.getTestId())) {
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
apiTestCase.setLastResultId(dto.getReportId());
apiTestCase.setId(dto.getTestId());

View File

@ -805,6 +805,7 @@ public class TestPlanApiCaseService {
request.setEnvironmentId(testPlanApiCase.getEnvironmentId());
request.setBloBs(apiCase);
request.setReportId(reportId);
request.setTestPlanId(testPlanApiCase.getTestPlanId());
Map<String, Object> extendedParameters = new HashMap<>();
extendedParameters.put(ExtendedParameter.SYNC_STATUS, true);
apiExecuteService.exec(request, extendedParameters);

View File

@ -45,7 +45,7 @@ const message = {
no_data: 'No data',
load_error: 'Load error',
this_week: 'Week',
fake_error: 'Fake error',
fake_error: 'FakeError',
executed_times_in_week: 'Executed in week',
executed_times: 'Executed in history',
covered: 'Covered',

View File

@ -227,6 +227,6 @@ plan_warning=The test plan does not have an associated executable use case
test_plan_delete_exec_error=The test plan is being executed
test_case_review_status_underway=Underway
test_case_review_status_re_review=ReReview
api_status_fake_error=Fake error
api_status_fake_error=FakeError
serial=Serial
parallel=Parallel