refactor(测试计划执行): 优化测试计划执行状态监听
优化测试计划执行状态监听,支持分布式部署下的执行结果查询
This commit is contained in:
parent
6be05e2c17
commit
a46696fd6a
|
@ -34,6 +34,7 @@ public class TestPlanExecuteInfo {
|
|||
private Map<String, String> apiScenarioCaseExecInfo = new ConcurrentHashMap<>();
|
||||
private Map<String, String> loadCaseExecInfo = new ConcurrentHashMap<>();
|
||||
|
||||
//案例线程是以reportID为id的。 key:关联表ID value:reportID
|
||||
private Map<String, String> apiCaseExecuteThreadMap = new ConcurrentHashMap<>();
|
||||
private Map<String, String> apiScenarioThreadMap = new ConcurrentHashMap<>();
|
||||
private Map<String, String> loadCaseReportIdMap = new ConcurrentHashMap<>();
|
||||
|
@ -238,4 +239,30 @@ public class TestPlanExecuteInfo {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public Map<String, String> getRunningApiCaseReportMap() {
|
||||
//key: reportId, value: testPlanApiCaseId
|
||||
Map<String, String> returnMap = new HashMap<>();
|
||||
for (String result : apiCaseExecInfo.keySet()) {
|
||||
if (StringUtils.equalsIgnoreCase(result, TestPlanApiExecuteStatus.RUNNING.name())) {
|
||||
if (apiCaseExecuteThreadMap.containsKey(result)) {
|
||||
returnMap.put(apiCaseExecuteThreadMap.get(result), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getRunningScenarioReportMap() {
|
||||
//key: reportId, value: testPlanApiScenarioId
|
||||
Map<String, String> returnMap = new HashMap<>();
|
||||
for (String result : apiScenarioCaseExecInfo.keySet()) {
|
||||
if (StringUtils.equalsIgnoreCase(result, TestPlanApiExecuteStatus.RUNNING.name())) {
|
||||
if (apiScenarioThreadMap.containsKey(result)) {
|
||||
returnMap.put(apiScenarioThreadMap.get(result), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
}
|
|
@ -81,11 +81,15 @@ public class TestPlanReportService {
|
|||
@Resource
|
||||
ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
|
||||
@Resource
|
||||
ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
LoadTestReportMapper loadTestReportMapper;
|
||||
@Resource
|
||||
TestPlanLoadCaseMapper testPlanLoadCaseMapper;
|
||||
@Resource
|
||||
ExtApiScenarioReportMapper extApiScenarioReportMapper;
|
||||
@Lazy
|
||||
@Resource
|
||||
TestPlanService testPlanService;
|
||||
|
@ -1251,6 +1255,14 @@ public class TestPlanReportService {
|
|||
}
|
||||
|
||||
private boolean checkTestPlanReportIsTimeOut(String planReportId) {
|
||||
//同步数据库更新状态信息
|
||||
try {
|
||||
this.syncReportStatus(planReportId);
|
||||
} catch (Exception e) {
|
||||
LogUtil.info("联动数据库同步执行状态失败! " + e.getMessage());
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
||||
TestPlanExecuteInfo executeInfo = TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId);
|
||||
int unFinishNum = executeInfo.countUnFinishedNum();
|
||||
if (unFinishNum > 0) {
|
||||
|
@ -1264,6 +1276,49 @@ public class TestPlanReportService {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void syncReportStatus(String planReportId) {
|
||||
if (TestPlanReportExecuteCatch.containsReport(planReportId)) {
|
||||
TestPlanExecuteInfo executeInfo = TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId);
|
||||
if (executeInfo != null) {
|
||||
//同步接口案例结果
|
||||
Map<String, String> updateCaseStatusMap = new HashMap<>();
|
||||
Map<String, String> apiCaseReportMap = executeInfo.getRunningApiCaseReportMap();
|
||||
if (MapUtils.isNotEmpty(apiCaseReportMap)) {
|
||||
List<ApiDefinitionExecResult> execList = extApiDefinitionExecResultMapper.selectStatusByIdList(apiCaseReportMap.keySet());
|
||||
for (ApiDefinitionExecResult report : execList) {
|
||||
String reportId = report.getId();
|
||||
String status = report.getStatus();
|
||||
if (!StringUtils.equalsAnyIgnoreCase(status, "Running", "Waiting")) {
|
||||
String planCaseId = apiCaseReportMap.get(reportId);
|
||||
if (StringUtils.isNotEmpty(planCaseId)) {
|
||||
updateCaseStatusMap.put(planCaseId, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//同步场景结果
|
||||
Map<String, String> updateScenarioStatusMap = new HashMap<>();
|
||||
Map<String, String> scenarioReportMap = executeInfo.getRunningScenarioReportMap();
|
||||
if (MapUtils.isNotEmpty(scenarioReportMap)) {
|
||||
List<ApiScenarioReport> reportList = extApiScenarioReportMapper.selectStatusByIds(scenarioReportMap.keySet());
|
||||
for (ApiScenarioReport report : reportList) {
|
||||
String reportId = report.getId();
|
||||
String status = report.getStatus();
|
||||
if (!StringUtils.equalsAnyIgnoreCase(status, "Running", "Waiting")) {
|
||||
String planScenarioId = scenarioReportMap.get(reportId);
|
||||
if (StringUtils.isNotEmpty(planScenarioId)) {
|
||||
updateScenarioStatusMap.put(planScenarioId, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId, updateCaseStatusMap, updateScenarioStatusMap, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void finishTestPlanReport(String planReportId) {
|
||||
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId);
|
||||
if (testPlanReport != null && StringUtils.equalsIgnoreCase("Running", testPlanReport.getStatus())) {
|
||||
|
|
Loading…
Reference in New Issue