fix(接口测试): 修复单条执行用例偶发获取不到结果问题
--bug=1009232 --user=赵勇 【接口测试】执行测试用例还是一直执行中【+github#8807】 https://www.tapd.cn/55049933/s/1089188
This commit is contained in:
parent
e4633d707a
commit
7dbb81f9a7
|
@ -285,12 +285,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
||||
//增加误报、断言
|
||||
if (httpConfig != null) {
|
||||
if(CollectionUtils.isNotEmpty(httpConfig.getErrorReportAssertions())){
|
||||
if (CollectionUtils.isNotEmpty(httpConfig.getErrorReportAssertions())) {
|
||||
for (MsAssertions assertion : httpConfig.getErrorReportAssertions()) {
|
||||
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
|
||||
}
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(httpConfig.getAssertions())){
|
||||
if (CollectionUtils.isNotEmpty(httpConfig.getAssertions())) {
|
||||
for (MsAssertions assertion : httpConfig.getAssertions()) {
|
||||
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
httpConfig.setPostProcessor(environmentConfig.getPostProcessor());
|
||||
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
|
||||
httpConfig.setAssertions(environmentConfig.getAssertions());
|
||||
if(environmentConfig.isUseErrorCode()){
|
||||
if (environmentConfig.isUseErrorCode()) {
|
||||
httpConfig.setErrorReportAssertions(HashTreeUtil.getErrorReportByProjectId(this.getProjectId()));
|
||||
}
|
||||
return httpConfig;
|
||||
|
@ -749,22 +749,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
list.stream().
|
||||
filter(KeyValue::isValid).
|
||||
filter(KeyValue::isEnable).forEach(keyValue -> {
|
||||
try {
|
||||
String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value);
|
||||
if (keyValue.getValue() == null) {
|
||||
httpArgument.setValue("");
|
||||
}
|
||||
httpArgument.setAlwaysEncoded(keyValue.isUrlEncode());
|
||||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||
httpArgument.setContentType(keyValue.getContentType());
|
||||
}
|
||||
arguments.addArgument(httpArgument);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value);
|
||||
if (keyValue.getValue() == null) {
|
||||
httpArgument.setValue("");
|
||||
}
|
||||
);
|
||||
httpArgument.setAlwaysEncoded(keyValue.isUrlEncode());
|
||||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||
httpArgument.setContentType(keyValue.getContentType());
|
||||
}
|
||||
arguments.addArgument(httpArgument);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
@ -836,21 +836,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
} else {
|
||||
apiDefinition = apiDefinitionService.get(this.getId());
|
||||
if (apiDefinition == null) {
|
||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(this.getId());
|
||||
if (apiTestCaseWithBLOBs == null) {
|
||||
apiTestCaseWithBLOBs = apiTestCaseService.get(this.getName());
|
||||
}
|
||||
if (apiTestCaseWithBLOBs != null) {
|
||||
apiDefinition = apiDefinitionService.get(apiTestCaseWithBLOBs.getApiDefinitionId());
|
||||
} else {
|
||||
TestPlanApiCaseService testPlanApiCaseService = CommonBeanFactory.getBean(TestPlanApiCaseService.class);
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(this.getId());
|
||||
if (testPlanApiCase != null) {
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
||||
if (caseWithBLOBs != null) {
|
||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||
}
|
||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(this.getId());
|
||||
if (apiTestCaseWithBLOBs == null) {
|
||||
apiTestCaseWithBLOBs = apiTestCaseService.get(this.getName());
|
||||
}
|
||||
if (apiTestCaseWithBLOBs != null) {
|
||||
apiDefinition = apiDefinitionService.get(apiTestCaseWithBLOBs.getApiDefinitionId());
|
||||
} else {
|
||||
TestPlanApiCaseService testPlanApiCaseService = CommonBeanFactory.getBean(TestPlanApiCaseService.class);
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(this.getId());
|
||||
if (testPlanApiCase != null) {
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
||||
if (caseWithBLOBs != null) {
|
||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,11 @@ public class APISingleResultListener extends MsExecListener {
|
|||
dto.setConsole(CommonBeanFactory.getBean(MsResultService.class).getJmeterLogger(dto.getReportId()));
|
||||
// 整体执行结束更新资源状态
|
||||
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
|
||||
|
||||
LoggerUtil.info("执行队列处理:" + dto.getQueueId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
if (StringUtils.isNotEmpty(dto.getQueueId())) {
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error(e);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.cache.TestPlanReportExecuteCatch;
|
||||
import io.metersphere.api.dto.ErrorReportLibraryParseDTO;
|
||||
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
|
@ -13,7 +12,6 @@ import io.metersphere.base.mapper.TestCaseReviewApiCaseMapper;
|
|||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
import io.metersphere.commons.utils.ErrorReportLibraryUtil;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
|
@ -66,6 +64,7 @@ public class ApiDefinitionExecResultService {
|
|||
private TestPlanTestCaseService testPlanTestCaseService;
|
||||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
|
||||
public void saveApiResult(List<RequestResult> requestResults, ResultDTO dto) {
|
||||
boolean isFirst = true;
|
||||
int count = requestResults.stream()
|
||||
|
@ -322,7 +321,6 @@ 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_")) {
|
||||
ErrorReportLibraryParseDTO errorCodeDTO = ErrorReportLibraryUtil.parseAssertions(item);
|
||||
ApiDefinitionExecResult saveResult = apiDefinitionExecResultMapper.selectByPrimaryKey(reportId);
|
||||
if (saveResult == null) {
|
||||
saveResult = new ApiDefinitionExecResult();
|
||||
|
@ -334,10 +332,6 @@ public class ApiDefinitionExecResultService {
|
|||
saveResult.setType(type);
|
||||
saveResult.setCreateTime(item.getStartTime());
|
||||
String status = item.isSuccess() ? ExecuteResult.success.name() : ExecuteResult.error.name();
|
||||
if(errorCodeDTO.getErrorCodeList() != null){
|
||||
status = ExecuteResult.errorCode.name();
|
||||
saveResult.setErrorCode(errorCodeDTO.getErrorCodeStr());
|
||||
}
|
||||
saveResult.setName(editStatus(type, status, saveResult.getCreateTime(), saveResult.getId(), testId));
|
||||
saveResult.setStatus(status);
|
||||
saveResult.setResourceId(item.getName());
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package io.metersphere.websocket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.APIReportResult;
|
||||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -87,6 +91,7 @@ public class ApiReportWebSocket {
|
|||
this.runMode = runMode;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -95,10 +100,15 @@ public class ApiReportWebSocket {
|
|||
return;
|
||||
}
|
||||
if (report != null) {
|
||||
session.getBasicRemote().sendText(report.getContent());
|
||||
if (StringUtils.isNotEmpty(report.getContent())) {
|
||||
session.getBasicRemote().sendText(report.getContent());
|
||||
} else {
|
||||
session.getBasicRemote().sendText(JSON.toJSONString(new TestResult()));
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
session.close();
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue