fix(接口测试): 修复场景中调试状态未及时更新问题

This commit is contained in:
fit2-zhao 2021-12-23 12:20:07 +08:00 committed by fit2-zhao
parent 23a1793986
commit 67a143588c
5 changed files with 92 additions and 46 deletions

View File

@ -71,8 +71,10 @@ public class ApiScenarioSerialService {
apiScenarioReportMapper.updateByPrimaryKey(report);
} else {
ApiDefinitionExecResult execResult = apiDefinitionExecResultMapper.selectByPrimaryKey(queue.getReportId());
execResult.setStatus(APITestStatus.Running.name());
apiDefinitionExecResultMapper.updateByPrimaryKey(execResult);
if (execResult != null) {
execResult.setStatus(APITestStatus.Running.name());
apiDefinitionExecResultMapper.updateByPrimaryKey(execResult);
}
}
}

View File

@ -317,7 +317,10 @@ public class ApiDefinitionExecResultService {
private ApiDefinitionExecResult save(RequestResult item, String reportId, String console, int expectProcessResultCount, String type, String testId, boolean isFirst) {
if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) {
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
ApiDefinitionExecResult saveResult = apiDefinitionExecResultMapper.selectByPrimaryKey(reportId);
if (saveResult == null) {
saveResult = new ApiDefinitionExecResult();
}
item.getResponseResult().setConsole(console);
saveResult.setId(reportId);
saveResult.setActuator("LOCAL");

View File

@ -87,7 +87,6 @@ public class ApiScenarioReportService {
apiScenarioReportResultService.save(dto.getReportId(), requestResults);
}
public ApiScenarioReport testEnded(ResultDTO dto) {
if (!StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
// 更新控制台信息
@ -179,38 +178,26 @@ public class ApiScenarioReportService {
}
public ApiScenarioReport editReport(String reportType, String reportId, String status, String runMode) {
try {
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
if (report == null) {
int index = 0;
while (index < 3) {
LogUtil.info("未获取到报告,尝试重新获取:【" + reportId + "");
report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
Thread.sleep(2000);
index++;
}
}
if (report != null) {
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
return report;
}
if (runMode.equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
report.setStatus(status);
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
report.setEndTime(System.currentTimeMillis());
report.setUpdateTime(System.currentTimeMillis());
if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
}
return report;
} catch (Exception e) {
LoggerUtil.error(e);
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
if (report == null) {
report = new ApiScenarioReport();
report.setId(reportId);
}
return null;
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
return report;
}
if (runMode.equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
report.setStatus(status);
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
report.setEndTime(System.currentTimeMillis());
report.setUpdateTime(System.currentTimeMillis());
if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
return report;
}
public ApiScenarioReport updateReport(APIScenarioReportResult test) {

View File

@ -1144,6 +1144,7 @@ export default {
this.clearDebug();
this.clearResult(this.scenarioDefinition);
this.clearNodeStatus(this.$refs.stepTree.root.childNodes);
this.sort();
/*触发执行操作*/
this.$refs.currentScenario.validate(async (valid) => {
if (valid) {

View File

@ -18,7 +18,16 @@
:node="node"
:is-read-only="this.jsr223Processor.disabled"/>
</legend>
<template v-slot:debugStepCode>
<span v-if="jsr223Processor.testing" class="ms-test-running">
<i class="el-icon-loading" style="font-size: 16px"/>
{{ $t('commons.testing') }}
</span>
<span class="ms-step-debug-code" :class="jsr223Processor.requestResult[0].success && reqSuccess?'ms-req-success':'ms-req-error'"
v-if="!loading &&!jsr223Processor.testing && jsr223Processor.debug && jsr223Processor.requestResult[0] && jsr223Processor.requestResult[0].responseResult">
{{ jsr223Processor.requestResult[0].success && reqSuccess ? 'success' : 'error' }}
</span>
</template>
</api-base-component>
</template>
@ -33,6 +42,8 @@ export default {
name: "MsJsr233Processor",
components: {Jsr233ProcessorContent, ApiBaseComponent, MsDropdown, MsInstructionsIcon, MsCodeEdit},
props: {
request: {},
message: String,
draggable: {
type: Boolean,
default: false,
@ -48,11 +59,11 @@ export default {
isReadOnly: {
type: Boolean,
default:
false
},
jsr223Processor: {
type: Object,
},
false
},
jsr223Processor: {
type: Object,
},
isPreProcessor: {
type: Boolean,
default:
@ -63,10 +74,39 @@ export default {
backgroundColor: String,
node: {},
},
watch: {
message() {
this.forStatus();
this.reload();
},
},
data() {
return {loading: false}
return {
loading: false,
reqSuccess: true
}
},
methods: {
forStatus() {
if (this.jsr223Processor && this.jsr223Processor.result && this.jsr223Processor.result.length > 0) {
this.jsr223Processor.result.forEach(item => {
item.requestResult.forEach(req => {
if (!req.success) {
this.reqSuccess = req.success;
}
})
})
} else if (this.jsr223Processor && this.jsr223Processor.requestResult && this.jsr223Processor.requestResult.length > 1) {
this.jsr223Processor.requestResult.forEach(item => {
if (!item.success) {
this.reqSuccess = item.success;
if (this.node && this.node.parent && this.node.parent.data) {
this.node.parent.data.code = 'error';
}
}
})
}
},
remove() {
this.$emit('remove', this.jsr223Processor, this.node);
},
@ -84,11 +124,24 @@ export default {
this.reload();
},
}
}
}
</script>
<style scoped>
/deep/ .el-divider {
margin-bottom: 10px;
}
/deep/ .el-divider {
margin-bottom: 10px;
}
.ms-req-error {
color: #F56C6C;
}
.ms-test-running {
color: #6D317C;
}
.ms-req-success {
color: #67C23A;
}
</style>