fix(场景自动化) 增加部分输出便与判断集成进度

This commit is contained in:
fit2-zhao 2021-09-16 15:59:44 +08:00 committed by fit2-zhao
parent 744b9895d5
commit 305db60aea
4 changed files with 48 additions and 47 deletions

View File

@ -24,28 +24,33 @@ public class FixedTask {
if (MessageCache.cache != null && MessageCache.cache.size() > 0) {
for (String key : MessageCache.cache.keySet()) {
ReportCounter counter = MessageCache.cache.get(key);
LogUtil.info("集成报告:【" + key + "】总执行场景:【" + counter.getReportIds().size() + "】已经执行完成场景:【" + counter.getNumber() + "");
// 合并
if (counter.getNumber() == counter.getReportIds().size()) {
scenarioReportService.margeReport(key, counter.getReportIds());
guardTask.remove(key);
MessageCache.cache.remove(key);
} else {
int number = 0;
if (guardTask.containsKey(key)) {
number = guardTask.get(key);
guardTask.put(key, number++);
} else {
guardTask.put(key, number);
}
if (CollectionUtils.isNotEmpty(counter.getPoolUrls()) && counter.getNumber() > 0 && guardTask.get(key) > 200) {
// 资源池中已经没有执行的请求了
int runningCount = scenarioReportService.get(key, counter);
if (runningCount == 0) {
LogUtil.info("发生未知异常,进行资源合并,请检查资源池是否正常运行");
scenarioReportService.margeReport(key, counter.getReportIds());
guardTask.remove(key);
MessageCache.cache.remove(key);
try {
int number = 0;
if (guardTask.containsKey(key)) {
number = guardTask.get(key);
guardTask.put(key, number++);
} else {
guardTask.put(key, number);
}
if (CollectionUtils.isNotEmpty(counter.getPoolUrls()) && counter.getNumber() > 0 && guardTask.get(key) > 200) {
// 资源池中已经没有执行的请求了
int runningCount = scenarioReportService.get(key, counter);
if (runningCount == 0) {
LogUtil.info("发生未知异常,进行资源合并,请检查资源池是否正常运行");
scenarioReportService.margeReport(key, counter.getReportIds());
guardTask.remove(key);
MessageCache.cache.remove(key);
}
}
} catch (Exception ex) {
LogUtil.error(ex.getMessage());
}
}
}

View File

@ -44,13 +44,14 @@ public class TestResult {
private List<ScenarioResult> scenarios = new ArrayList<>();
private Map<String, Boolean> margeScenariMap = new HashMap<>();
private Map<String, Boolean> margeScenarioMap = new HashMap<>();
private Map<String, Boolean> scenarioStepMap = new HashMap<>();
private int scenarioStepSuccess = 0;
private int scenarioStepError = 0;
private int scenarioStepTotal = 0;
public void addError(int count) {
this.error += count;
}
@ -72,16 +73,16 @@ public class TestResult {
private void setStatus(List<String> id_names, boolean status) {
if (CollectionUtils.isNotEmpty(id_names)) {
id_names.forEach(item -> {
if (!margeScenariMap.containsKey(item) || status) {
margeScenariMap.put(item, status);
if (!margeScenarioMap.containsKey(item) || status) {
margeScenarioMap.put(item, status);
}
});
}
}
private void setStatus(String id_names, boolean status) {
if (!margeScenariMap.containsKey(id_names) || status) {
margeScenariMap.put(id_names, status);
if (!margeScenarioMap.containsKey(id_names) || status) {
margeScenarioMap.put(id_names, status);
}
}
@ -101,18 +102,18 @@ public class TestResult {
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
result.getRequestResults().forEach(item -> {
String itemAndScenarioName = "";
if (StringUtils.isNotEmpty(item.getScenario())) {
if (StringUtils.isNotEmpty(item.getScenario())) {
//第1个当前场景 第all_id_names个最后一层场景
List<String> all_id_names = JSON.parseObject(item.getScenario(), List.class);
if(all_id_names.size()>1){
if (all_id_names.size() > 1) {
StringBuffer scenarioNames = new StringBuffer();
//因为要进行步骤统计第一层级下的场景算作步骤所以统计视角只按照第一级别场景来计算
scenarioNames.append(all_id_names.get(all_id_names.size()-1)+all_id_names.get(all_id_names.size()-2));
scenarioNames.append(all_id_names.get(all_id_names.size() - 1) + all_id_names.get(all_id_names.size() - 2));
this.setStatus(scenarioNames.toString(), item.getError() > 0);
itemAndScenarioName = scenarioNames.toString();
}else{
} else {
//不存在多场景时需要补上步骤名字做唯一判断 添加UUID进行处理
itemAndScenarioName = item.getName()+":"+JSONArray.toJSONString(all_id_names.get(0))+ UUID.randomUUID().toString();
itemAndScenarioName = item.getName() + ":" + JSONArray.toJSONString(all_id_names.get(0)) + UUID.randomUUID().toString();
this.setStatus(all_id_names, item.getError() > 0);
}
@ -124,9 +125,9 @@ public class TestResult {
subItem.setName(array[0]);
});
} else {
this.genScenarioInSubReqeustResult(item);
this.genScenarioInSubRequestResult(item);
}
this.setStepStatus(itemAndScenarioName,item.getError()>0);
this.setStepStatus(itemAndScenarioName, item.getError() > 0);
});
scenarios.add(result);
}
@ -134,23 +135,23 @@ public class TestResult {
* 1.10.2 场景成功/失败统计不再按照请求为纬度按照场景为纬度
*/
for (String key : scenarioStepMap.keySet()) {
if (scenarioStepMap .get(key)) {
if (scenarioStepMap.get(key)) {
this.scenarioStepError++;
} else {
this.scenarioStepSuccess++;
}
}
boolean hasError = false;
for (String key : margeScenariMap.keySet()) {
if (margeScenariMap.get(key)) {
for (String key : margeScenarioMap.keySet()) {
if (margeScenarioMap.get(key)) {
hasError = true;
break;
}
}
if(!margeScenariMap.isEmpty()){
if(hasError){
this.scenarioError ++;
}else {
if (!margeScenarioMap.isEmpty()) {
if (hasError) {
this.scenarioError++;
} else {
this.scenarioSuccess++;
}
this.scenarioTotal++;
@ -162,21 +163,21 @@ public class TestResult {
}
//一般多层的事务控制器会出现这种情况
private String genScenarioInSubReqeustResult(RequestResult item) {
private String genScenarioInSubRequestResult(RequestResult item) {
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
String array[] = item.getName().split(SEPARATOR);
item.setName(array[0]);
}
if(StringUtils.isNotEmpty(item.getScenario())){
if (StringUtils.isNotEmpty(item.getScenario())) {
List<String> id_names = JSON.parseObject(item.getScenario(), List.class);
this.setStatus(id_names, item.getError() > 0);
return item.getScenario();
}else{
if(CollectionUtils.isNotEmpty(item.getSubRequestResults())){
for (RequestResult requestResult:item.getSubRequestResults()) {
String result = this.genScenarioInSubReqeustResult(requestResult);
} else {
if (CollectionUtils.isNotEmpty(item.getSubRequestResults())) {
for (RequestResult requestResult : item.getSubRequestResults()) {
this.genScenarioInSubRequestResult(requestResult);
}
}
return null;

View File

@ -1098,6 +1098,7 @@ public class ApiAutomationService {
counter.setPoolUrls(request.getConfig().getTestResources());
}
counter.setReportIds(reportIds);
request.getConfig().setAmassReport(serialReportId);
MessageCache.cache.put(serialReportId, counter);
}
}

View File

@ -41,7 +41,6 @@ import io.metersphere.log.vo.api.ModuleReference;
import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.service.NoticeSendService;
import io.metersphere.service.UserService;
import io.metersphere.track.service.TestPlanReportService;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -292,7 +291,6 @@ public class ApiScenarioReportService {
returnReport = report;
reportIds.add(report.getId());
}
// margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds);
return returnReport;
}
@ -401,10 +399,7 @@ public class ApiScenarioReportService {
caseReportMap.put(testPlanApiScenario.getApiScenarioId(), reportResult);
reportIds.add(report.getId());
}
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
testPlanLog.info("TestPlanReportId" + JSONArray.toJSONString(testPlanReportIdList) + " EXECUTE OVER. SCENARIO STATUS : " + JSONObject.toJSONString(scenarioAndErrorMap));
for (String reportId : testPlanReportIdList) {
TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(reportId, null, scenarioAndErrorMap, null);
TestPlanReportExecuteCatch.updateTestPlanExecuteResultInfo(reportId, null, caseReportMap, null);
@ -868,8 +863,7 @@ public class ApiScenarioReportService {
}
}
} catch (Exception e) {
e.printStackTrace();
MSException.throwException(e.getMessage());
LogUtil.error(e.getMessage());
}
return count;
}