fix(接口测试): 修复集合报告操作日志偶发为空的情况
--bug=1013615 --user=赵勇 【接口测试】批量执行case和场景,集合报告,控制台是空白的 https://www.tapd.cn/55049933/s/1167419
This commit is contained in:
parent
f80dfb477c
commit
9e96b6b384
|
@ -6,6 +6,7 @@ import io.metersphere.api.service.ApiExecutionQueueService;
|
||||||
import io.metersphere.api.service.TestResultService;
|
import io.metersphere.api.service.TestResultService;
|
||||||
import io.metersphere.cache.JMeterEngineCache;
|
import io.metersphere.cache.JMeterEngineCache;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.dto.ResultDTO;
|
import io.metersphere.dto.ResultDTO;
|
||||||
import io.metersphere.jmeter.JMeterBase;
|
import io.metersphere.jmeter.JMeterBase;
|
||||||
import io.metersphere.jmeter.MsExecListener;
|
import io.metersphere.jmeter.MsExecListener;
|
||||||
|
@ -51,7 +52,7 @@ public class APISingleResultListener implements MsExecListener {
|
||||||
|
|
||||||
JMeterBase.resultFormatting(queues, dto);
|
JMeterBase.resultFormatting(queues, dto);
|
||||||
|
|
||||||
dto.setConsole(FixedCapacityUtils.getJmeterLogger(dto.getReportId()));
|
dto.setConsole(FixedCapacityUtils.getJmeterLogger(dto.getReportId(), !StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())));
|
||||||
// 入库存储
|
// 入库存储
|
||||||
CommonBeanFactory.getBean(TestResultService.class).saveResults(dto);
|
CommonBeanFactory.getBean(TestResultService.class).saveResults(dto);
|
||||||
|
|
||||||
|
@ -75,9 +76,6 @@ public class APISingleResultListener implements MsExecListener {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LoggerUtil.error(e);
|
LoggerUtil.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (FixedCapacityUtils.jmeterLogTask.containsKey(dto.getReportId())) {
|
|
||||||
FixedCapacityUtils.jmeterLogTask.remove(dto.getReportId());
|
|
||||||
}
|
|
||||||
if (JMeterEngineCache.runningEngine.containsKey(dto.getReportId())) {
|
if (JMeterEngineCache.runningEngine.containsKey(dto.getReportId())) {
|
||||||
JMeterEngineCache.runningEngine.remove(dto.getReportId());
|
JMeterEngineCache.runningEngine.remove(dto.getReportId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ public class FixedCapacityUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getJmeterLogger(String testId) {
|
public static String getJmeterLogger(String reportId, boolean isClear) {
|
||||||
try {
|
try {
|
||||||
Long startTime = FixedCapacityUtils.jmeterLogTask.get(testId);
|
Long startTime = FixedCapacityUtils.jmeterLogTask.get(reportId);
|
||||||
if (startTime == null) {
|
if (startTime == null) {
|
||||||
startTime = FixedCapacityUtils.jmeterLogTask.get("[" + testId + "]");
|
startTime = FixedCapacityUtils.jmeterLogTask.get("[" + reportId + "]");
|
||||||
}
|
}
|
||||||
if (startTime == null) {
|
if (startTime == null) {
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
|
@ -47,9 +47,14 @@ public class FixedCapacityUtils {
|
||||||
String logMessage = FixedCapacityUtils.fixedCapacityCache.entrySet().stream()
|
String logMessage = FixedCapacityUtils.fixedCapacityCache.entrySet().stream()
|
||||||
.filter(map -> map.getKey() > finalStartTime && map.getKey() <= endTime)
|
.filter(map -> map.getKey() > finalStartTime && map.getKey() <= endTime)
|
||||||
.map(map -> map.getValue()).collect(Collectors.joining());
|
.map(map -> map.getValue()).collect(Collectors.joining());
|
||||||
|
|
||||||
return logMessage;
|
return logMessage;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
|
} finally {
|
||||||
|
if (isClear && FixedCapacityUtils.jmeterLogTask.containsKey(reportId)) {
|
||||||
|
FixedCapacityUtils.jmeterLogTask.remove(reportId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
|
||||||
dto.setReportId("send." + this.getName());
|
dto.setReportId("send." + this.getName());
|
||||||
dto.setToReport(this.getName());
|
dto.setToReport(this.getName());
|
||||||
|
|
||||||
String console = FixedCapacityUtils.getJmeterLogger(this.getName());
|
String console = FixedCapacityUtils.getJmeterLogger(this.getName(),false);
|
||||||
if (StringUtils.isNotEmpty(requestResult.getName()) && requestResult.getName().startsWith("Transaction=")) {
|
if (StringUtils.isNotEmpty(requestResult.getName()) && requestResult.getName().startsWith("Transaction=")) {
|
||||||
requestResult.getSubRequestResults().forEach(transactionResult -> {
|
requestResult.getSubRequestResults().forEach(transactionResult -> {
|
||||||
transactionResult.getResponseResult().setConsole(console);
|
transactionResult.getResponseResult().setConsole(console);
|
||||||
|
|
|
@ -218,7 +218,7 @@ public class ApiExecutionQueueService {
|
||||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||||
reportId = dto.getTestPlanReportId();
|
reportId = dto.getTestPlanReportId();
|
||||||
}
|
}
|
||||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode());
|
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ public class ApiExecutionQueueService {
|
||||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||||
reportId = dto.getTestPlanReportId();
|
reportId = dto.getTestPlanReportId();
|
||||||
}
|
}
|
||||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode());
|
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -341,7 +341,7 @@ public class ApiExecutionQueueService {
|
||||||
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
if (StringUtils.equalsIgnoreCase(dto.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||||
reportId = dto.getTestPlanReportId();
|
reportId = dto.getTestPlanReportId();
|
||||||
}
|
}
|
||||||
apiScenarioReportService.margeReport(reportId, dto.getRunMode());
|
apiScenarioReportService.margeReport(reportId, dto.getRunMode(), dto.getConsole());
|
||||||
}
|
}
|
||||||
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
||||||
LoggerUtil.info("Queue execution ends:" + dto.getQueueId());
|
LoggerUtil.info("Queue execution ends:" + dto.getQueueId());
|
||||||
|
|
|
@ -345,7 +345,7 @@ public class ApiScenarioReportService {
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void margeReport(String reportId, String runMode) {
|
public void margeReport(String reportId, String runMode, String console) {
|
||||||
// 更新场景状态
|
// 更新场景状态
|
||||||
if (StringUtils.equalsIgnoreCase(runMode, ApiRunMode.DEFINITION.name())) {
|
if (StringUtils.equalsIgnoreCase(runMode, ApiRunMode.DEFINITION.name())) {
|
||||||
ApiDefinitionExecResultWithBLOBs result = definitionExecResultMapper.selectByPrimaryKey(reportId);
|
ApiDefinitionExecResultWithBLOBs result = definitionExecResultMapper.selectByPrimaryKey(reportId);
|
||||||
|
@ -371,8 +371,15 @@ public class ApiScenarioReportService {
|
||||||
apiScenarioReportMapper.updateByPrimaryKey(report);
|
apiScenarioReportMapper.updateByPrimaryKey(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console = StringUtils.isNotEmpty(console) ? console : FixedCapacityUtils.getJmeterLogger(reportId, true);
|
||||||
|
if (StringUtils.isNotEmpty(console)) {
|
||||||
|
apiScenarioReportStructureService.update(reportId, console);
|
||||||
|
}
|
||||||
// 更新控制台信息
|
// 更新控制台信息
|
||||||
apiScenarioReportStructureService.update(reportId, FixedCapacityUtils.getJmeterLogger(reportId));
|
if (FixedCapacityUtils.jmeterLogTask.containsKey(reportId)) {
|
||||||
|
FixedCapacityUtils.jmeterLogTask.remove(reportId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiScenarioReport updateScenario(List<ApiScenarioReportResult> requestResults, ResultDTO dto) {
|
public ApiScenarioReport updateScenario(List<ApiScenarioReportResult> requestResults, ResultDTO dto) {
|
||||||
|
|
|
@ -50,8 +50,6 @@ public class ApiScenarioReportStructureService {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiDefinitionExecResultMapper definitionExecResultMapper;
|
private ApiDefinitionExecResultMapper definitionExecResultMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiScenarioReportResultService apiScenarioReportResultService;
|
|
||||||
@Resource
|
|
||||||
private ExtApiScenarioReportResultMapper extApiScenarioReportResultMapper;
|
private ExtApiScenarioReportResultMapper extApiScenarioReportResultMapper;
|
||||||
|
|
||||||
private static final List<String> requests = Arrays.asList("HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor", "AbstractSampler");
|
private static final List<String> requests = Arrays.asList("HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor", "AbstractSampler");
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class RemakeReportService {
|
||||||
LoggerUtil.info("进入异常结果处理报告【" + dto.getReportId() + " 】" + dto.getRunMode() + " 整体执行完成");
|
LoggerUtil.info("进入异常结果处理报告【" + dto.getReportId() + " 】" + dto.getRunMode() + " 整体执行完成");
|
||||||
// 全局并发队列
|
// 全局并发队列
|
||||||
PoolExecBlockingQueueUtil.offer(dto.getReportId());
|
PoolExecBlockingQueueUtil.offer(dto.getReportId());
|
||||||
String consoleMsg = FixedCapacityUtils.getJmeterLogger(dto.getReportId());
|
String consoleMsg = FixedCapacityUtils.getJmeterLogger(dto.getReportId(),true);
|
||||||
dto.setConsole(consoleMsg + "\n" + errorMsg);
|
dto.setConsole(consoleMsg + "\n" + errorMsg);
|
||||||
// 整体执行结束更新资源状态
|
// 整体执行结束更新资源状态
|
||||||
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
|
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
|
||||||
|
|
Loading…
Reference in New Issue