fix(接口自动化): 支持并发步骤执行
This commit is contained in:
parent
873d1a5792
commit
36de246a74
|
@ -141,11 +141,11 @@ public class MsResultCollector extends AbstractListenerElement implements Sample
|
|||
dto.setContent(e.getThreadGroup());
|
||||
dto.setReportId("send." + this.getName());
|
||||
dto.setToReport(this.getName());
|
||||
LogUtil.debug("send. " + this.getName());
|
||||
if (client != null) {
|
||||
client.send(JSON.toJSONString(dto));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.jmeter.*;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.AssertionResult;
|
||||
|
@ -57,7 +56,7 @@ public class MsResultService {
|
|||
this.processCache.put(key, testResult);
|
||||
}
|
||||
|
||||
public TestResult sysnSampleResult(String key) {
|
||||
public TestResult synSampleResult(String key) {
|
||||
if (key.startsWith("[") && key.endsWith("]")) {
|
||||
key = JSON.parseArray(key).get(0).toString();
|
||||
}
|
||||
|
@ -103,21 +102,18 @@ public class MsResultService {
|
|||
|
||||
public void formatTestResult(TestResult testResult, Map<String, ScenarioResult> scenarios, SampleResult result) {
|
||||
String scenarioName = StringUtils.substringBeforeLast(result.getThreadName(), THREAD_SPLIT);
|
||||
String index = StringUtils.substringAfterLast(result.getThreadName(), THREAD_SPLIT);
|
||||
String scenarioId = StringUtils.substringBefore(index, ID_SPLIT);
|
||||
ScenarioResult scenarioResult;
|
||||
if (!scenarios.containsKey(scenarioId)) {
|
||||
if (!scenarios.containsKey(scenarioName)) {
|
||||
scenarioResult = new ScenarioResult();
|
||||
try {
|
||||
scenarioResult.setId(Integer.parseInt(scenarioId));
|
||||
} catch (Exception e) {
|
||||
scenarioResult.setId(0);
|
||||
LogUtil.error("场景ID转换异常: " + e.getMessage());
|
||||
}
|
||||
scenarioResult.setId(1);
|
||||
if (StringUtils.equals(testResult.getTestId(), scenarioName)) {
|
||||
scenarioResult.setName(scenarioName);
|
||||
scenarios.put(scenarioId, scenarioResult);
|
||||
} else {
|
||||
scenarioResult = scenarios.get(scenarioId);
|
||||
scenarioResult.setName(testResult.getTestId());
|
||||
}
|
||||
scenarios.put(scenarioName, scenarioResult);
|
||||
} else {
|
||||
scenarioResult = scenarios.get(scenarioName);
|
||||
}
|
||||
if (result.isSuccessful()) {
|
||||
scenarioResult.addSuccess();
|
||||
|
|
|
@ -31,11 +31,6 @@ import java.util.Map;
|
|||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestResultService {
|
||||
|
||||
@Resource
|
||||
private APITestService apiTestService;
|
||||
@Resource
|
||||
private APIReportService apiReportService;
|
||||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
@Resource
|
||||
|
@ -56,11 +51,7 @@ public class TestResultService {
|
|||
ApiTestReport report = null;
|
||||
ApiTestReportVariable reportTask = null;
|
||||
String planScenarioId = null;
|
||||
// 这部分后续优化只留 DEFINITION 和 SCENARIO 两部分
|
||||
if (StringUtils.equals(runMode, ApiRunMode.DEBUG.name())) {
|
||||
report = apiReportService.get(debugReportId);
|
||||
apiReportService.complete(testResult, report);
|
||||
} else if (StringUtils.equals(runMode, ApiRunMode.DEFINITION.name())) {
|
||||
if (StringUtils.equals(runMode, ApiRunMode.DEFINITION.name())) {
|
||||
// 调试操作,不需要存储结果
|
||||
apiDefinitionService.addResult(testResult);
|
||||
if (StringUtils.isBlank(debugReportId)) {
|
||||
|
@ -132,10 +123,6 @@ public class TestResultService {
|
|||
testResult.setTestId(scenarioReport.getScenarioId());
|
||||
planScenarioId = scenarioReport.getTestPlanScenarioId();
|
||||
}
|
||||
} else {
|
||||
apiTestService.changeStatus(testId, APITestStatus.Completed);
|
||||
report = apiReportService.getRunningReport(testResult.getTestId());
|
||||
apiReportService.complete(testResult, report);
|
||||
}
|
||||
updateTestCaseStates(testResult, planScenarioId, runMode);
|
||||
List<String> ids = testPlanTestCaseService.getTestPlanTestCaseIds(testResult.getTestId());
|
||||
|
@ -154,7 +141,7 @@ public class TestResultService {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,10 +100,10 @@ public class ScenarioReportWebSocket {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
TestResult report = resultService.sysnSampleResult(reportId);
|
||||
if (!session.isOpen()) {
|
||||
return;
|
||||
}
|
||||
TestResult report = resultService.synSampleResult(reportId);
|
||||
if (report != null) {
|
||||
session.getBasicRemote().sendText(JSON.toJSONString(report));
|
||||
if (report.isEnd()) {
|
||||
|
|
Loading…
Reference in New Issue