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