fix(接口自动化): 修复执行没有结果返回时 频繁刷新问题
This commit is contained in:
parent
4aa1c0cf57
commit
260f88a1ee
|
@ -98,7 +98,6 @@ public class ApiAutomationController {
|
|||
@PostMapping(value = "/run/batch")
|
||||
public String runBatch(@RequestBody RunScenarioRequest request) {
|
||||
request.setExecuteType(ExecuteType.Saved.name());
|
||||
request.setRunMode(ApiRunMode.SCENARIO_BATCH.name());
|
||||
return apiAutomationService.run(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,8 +182,8 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, ApiRunMode.SCHEDULE_API_PLAN.name());
|
||||
List<String> testPlanReportIdList = new ArrayList<>();
|
||||
testPlanReportIdList.add(debugReportId);
|
||||
testPlanReportService.updateReport(testPlanReportIdList,ApiRunMode.SCHEDULE_API_PLAN.name(),ReportTriggerMode.SCHEDULE.name());
|
||||
}else {
|
||||
testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.SCHEDULE_API_PLAN.name(), ReportTriggerMode.SCHEDULE.name());
|
||||
} else {
|
||||
apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.name());
|
||||
}
|
||||
} else if (StringUtils.equalsAny(this.runMode, ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||
|
|
|
@ -417,16 +417,13 @@ public class ApiAutomationService {
|
|||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) {
|
||||
runMode = ApiRunMode.SCENARIO_PLAN.name();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_BATCH.name())) {
|
||||
runMode = ApiRunMode.SCENARIO_BATCH.name();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
runMode = ApiRunMode.DEFINITION.name();
|
||||
}
|
||||
// 调用执行方法
|
||||
List<String> reportIds = new LinkedList<>();
|
||||
HashTree hashTree = generateHashTree(apiScenarios, request, reportIds);
|
||||
jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), runMode);
|
||||
jMeterService.runDefinition(JSON.toJSONString(reportIds), hashTree, request.getReportId(), runMode);
|
||||
return request.getId();
|
||||
}
|
||||
|
||||
|
@ -502,7 +499,6 @@ public class ApiAutomationService {
|
|||
}
|
||||
List<TestPlanDTO> list = extTestPlanMapper.selectByIds(request.getPlanIds());
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ExtTestPlanMapper mapper = sqlSession.getMapper(ExtTestPlanMapper.class);
|
||||
ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
|
||||
ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
|
||||
|
||||
|
@ -608,15 +604,12 @@ public class ApiAutomationService {
|
|||
}
|
||||
apiScenarios = extApiScenarioMapper.selectIds(ids);
|
||||
String testName = "";
|
||||
if(!apiScenarios.isEmpty()){
|
||||
if (!apiScenarios.isEmpty()) {
|
||||
testName = apiScenarios.get(0).getName();
|
||||
}
|
||||
MsTestPlan testPlan = new MsTestPlan();
|
||||
testPlan.setHashTree(new LinkedList<>());
|
||||
|
||||
HashTree jmeterHashTree = generateHashTree(apiScenarios, request, false);
|
||||
|
||||
|
||||
HashTree jmeterHashTree = generateHashTree(apiScenarios, request, null);
|
||||
String jmx = testPlan.getJmx(jmeterHashTree);
|
||||
//将ThreadGroup的testname改为接口名称
|
||||
|
|
|
@ -15,17 +15,18 @@ import io.metersphere.base.mapper.ApiScenarioReportDetailMapper;
|
|||
import io.metersphere.base.mapper.ApiScenarioReportMapper;
|
||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
import io.metersphere.commons.utils.ServiceUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.track.service.TestPlanReportService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -51,6 +52,8 @@ public class ApiScenarioReportService {
|
|||
private ApiScenarioMapper apiScenarioMapper;
|
||||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
@Resource
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public ApiScenarioReport complete(TestResult result, String runMode) {
|
||||
// 更新场景
|
||||
|
@ -60,6 +63,7 @@ public class ApiScenarioReportService {
|
|||
} else if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||
return updateSchedulePlanCase(result);
|
||||
} else {
|
||||
updateScenarioStatus(result.getTestId());
|
||||
return updateScenario(result);
|
||||
}
|
||||
}
|
||||
|
@ -217,13 +221,38 @@ public class ApiScenarioReportService {
|
|||
return lastReport;
|
||||
}
|
||||
|
||||
public ApiScenarioReport updateScenario(TestResult result) {
|
||||
if (CollectionUtils.isEmpty(result.getScenarios())) {
|
||||
ScenarioResult test = new ScenarioResult();
|
||||
test.setName(result.getTestId());
|
||||
ApiScenarioReport report = editReport(test);
|
||||
return report;
|
||||
/**
|
||||
* 批量更新状态,防止重复刷新报告
|
||||
*
|
||||
* @param reportIds
|
||||
*/
|
||||
private void updateScenarioStatus(String reportIds) {
|
||||
|
||||
if (StringUtils.isNotEmpty(reportIds)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
list = JSON.parseArray(reportIds, String.class);
|
||||
} catch (Exception e) {
|
||||
list.add(reportIds);
|
||||
}
|
||||
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
|
||||
scenarioReportExample.createCriteria().andIdIn(list);
|
||||
List<ApiScenarioReport> reportList = apiScenarioReportMapper.selectByExample(scenarioReportExample);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiScenarioReportMapper scenarioReportMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
|
||||
if (CollectionUtils.isNotEmpty(reportList)) {
|
||||
reportList.forEach(report -> {
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
String status = "Success";
|
||||
report.setStatus(status);
|
||||
scenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ApiScenarioReport updateScenario(TestResult result) {
|
||||
ApiScenarioReport lastReport = null;
|
||||
for (ScenarioResult item : result.getScenarios()) {
|
||||
// 更新报告状态
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum ApiRunMode {
|
||||
RUN, DEBUG, DEFINITION,SCENARIO, API_PLAN, SCENARIO_PLAN,SCENARIO_BATCH,API,SCHEDULE_API_PLAN,SCHEDULE_SCENARIO_PLAN,SCHEDULE_PERFORMANCE_TEST
|
||||
RUN, DEBUG, DEFINITION,SCENARIO, API_PLAN, SCENARIO_PLAN,API,SCHEDULE_API_PLAN,SCHEDULE_SCENARIO_PLAN,SCHEDULE_PERFORMANCE_TEST
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue