fix(测试跟踪): 修复测试跟踪用例执行结果找不到问题。
This commit is contained in:
parent
6b8ba7b283
commit
facb132f91
|
@ -74,17 +74,6 @@ public class ApiDefinitionExecResultService {
|
||||||
saveResult.setName(item.getName());
|
saveResult.setName(item.getName());
|
||||||
saveResult.setTriggerMode(triggerMode);
|
saveResult.setTriggerMode(triggerMode);
|
||||||
saveResult.setType(type);
|
saveResult.setType(type);
|
||||||
if (!StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
|
||||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(item.getName());
|
|
||||||
if (apiDefinition != null) {
|
|
||||||
saveResult.setName(apiDefinition.getName());
|
|
||||||
} else {
|
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(item.getName());
|
|
||||||
if (caseWithBLOBs != null) {
|
|
||||||
saveResult.setName(caseWithBLOBs.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(result.getUserId())) {
|
if (StringUtils.isNotEmpty(result.getUserId())) {
|
||||||
saveResult.setUserId(result.getUserId());
|
saveResult.setUserId(result.getUserId());
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,34 +81,14 @@ public class ApiDefinitionExecResultService {
|
||||||
}
|
}
|
||||||
saved = false;
|
saved = false;
|
||||||
}
|
}
|
||||||
|
String status = item.isSuccess() ? "success" : "error";
|
||||||
|
saveResult.setName(getName(type, item.getName(), status, saveResult.getCreateTime()));
|
||||||
|
saveResult.setStatus(status);
|
||||||
saveResult.setCreateTime(item.getStartTime());
|
saveResult.setCreateTime(item.getStartTime());
|
||||||
if (item.getName().indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
|
|
||||||
saveResult.setName(item.getName().substring(0, item.getName().indexOf(DelimiterConstants.SEPARATOR.toString())));
|
|
||||||
}
|
|
||||||
saveResult.setResourceId(item.getName());
|
saveResult.setResourceId(item.getName());
|
||||||
saveResult.setContent(JSON.toJSONString(item));
|
saveResult.setContent(JSON.toJSONString(item));
|
||||||
saveResult.setStartTime(item.getStartTime());
|
saveResult.setStartTime(item.getStartTime());
|
||||||
String status = item.isSuccess() ? "success" : "error";
|
|
||||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||||
saveResult.setStatus(status);
|
|
||||||
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
|
||||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(item.getName());
|
|
||||||
String id = null;
|
|
||||||
if (testPlanApiCase != null) {
|
|
||||||
testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
|
||||||
id = testPlanApiCase.getApiCaseId();
|
|
||||||
}
|
|
||||||
TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(item.getName());
|
|
||||||
if (testCaseReviewApiCase != null) {
|
|
||||||
testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
|
||||||
id = testCaseReviewApiCase.getApiCaseId();
|
|
||||||
}
|
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(id);
|
|
||||||
if (caseWithBLOBs != null) {
|
|
||||||
saveResult.setName(caseWithBLOBs.getName());
|
|
||||||
saveResult.setResourceId(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清空上次执行结果的内容,只保留当前最新一条内容
|
// 清空上次执行结果的内容,只保留当前最新一条内容
|
||||||
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type);
|
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type);
|
||||||
|
@ -145,6 +114,39 @@ public class ApiDefinitionExecResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getName(String type, String id, String status, Long time) {
|
||||||
|
if (id.indexOf(DelimiterConstants.SEPARATOR.toString()) != -1) {
|
||||||
|
return id.substring(0, id.indexOf(DelimiterConstants.SEPARATOR.toString()));
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
||||||
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(id);
|
||||||
|
ApiTestCaseWithBLOBs caseWithBLOBs = null;
|
||||||
|
if (testPlanApiCase != null) {
|
||||||
|
testPlanApiCaseService.setExecResult(id, status, time);
|
||||||
|
caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testPlanApiCase.getApiCaseId());
|
||||||
|
}
|
||||||
|
TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(id);
|
||||||
|
if (testCaseReviewApiCase != null) {
|
||||||
|
testCaseReviewApiCaseService.setExecResult(id, status, time);
|
||||||
|
caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testCaseReviewApiCase.getApiCaseId());
|
||||||
|
}
|
||||||
|
if (caseWithBLOBs != null) {
|
||||||
|
return caseWithBLOBs.getName();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
|
if (apiDefinition != null) {
|
||||||
|
return apiDefinition.getName();
|
||||||
|
} else {
|
||||||
|
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(id);
|
||||||
|
if (caseWithBLOBs != null) {
|
||||||
|
return caseWithBLOBs.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务触发的保存逻辑
|
* 定时任务触发的保存逻辑
|
||||||
* 定时任务时,userID要改为定时任务中的用户
|
* 定时任务时,userID要改为定时任务中的用户
|
||||||
|
|
|
@ -18,7 +18,9 @@
|
||||||
(select t.id,t.name,'API' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, ifnull(t.trigger_mode,'MANUAL') as triggerMode ,ifnull(t.status,'Saved') as executionStatus
|
(select t.id,t.name,'API' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, ifnull(t.trigger_mode,'MANUAL') as triggerMode ,ifnull(t.status,'Saved') as executionStatus
|
||||||
from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
|
from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
|
||||||
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
|
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
|
||||||
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId})
|
left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id
|
||||||
|
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and
|
||||||
|
(t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId})
|
||||||
<if test="request.triggerMode != null and request.triggerMode != ''">
|
<if test="request.triggerMode != null and request.triggerMode != ''">
|
||||||
and t.trigger_mode = #{request.triggerMode}
|
and t.trigger_mode = #{request.triggerMode}
|
||||||
</if>
|
</if>
|
||||||
|
@ -51,7 +53,8 @@
|
||||||
(select t.id,t.create_time as executionTime
|
(select t.id,t.create_time as executionTime
|
||||||
from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
|
from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
|
||||||
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
|
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
|
||||||
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId}) and t.status not in ("saved","completed","success","error")
|
left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id
|
||||||
|
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId}) and t.status not in ("saved","completed","success","error")
|
||||||
)
|
)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(select t.id,t.create_time as executionTime
|
(select t.id,t.create_time as executionTime
|
||||||
|
|
|
@ -3,9 +3,11 @@ package io.metersphere.task.service;
|
||||||
import io.metersphere.base.mapper.ext.ExtTaskMapper;
|
import io.metersphere.base.mapper.ext.ExtTaskMapper;
|
||||||
import io.metersphere.task.dto.TaskCenterDTO;
|
import io.metersphere.task.dto.TaskCenterDTO;
|
||||||
import io.metersphere.task.dto.TaskCenterRequest;
|
import io.metersphere.task.dto.TaskCenterRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -14,10 +16,16 @@ public class TaskService {
|
||||||
private ExtTaskMapper extTaskMapper;
|
private ExtTaskMapper extTaskMapper;
|
||||||
|
|
||||||
public List<TaskCenterDTO> getTasks(TaskCenterRequest request) {
|
public List<TaskCenterDTO> getTasks(TaskCenterRequest request) {
|
||||||
|
if (StringUtils.isEmpty(request.getProjectId())) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
return extTaskMapper.getTasks(request);
|
return extTaskMapper.getTasks(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TaskCenterDTO> getRunningTasks(TaskCenterRequest request) {
|
public List<TaskCenterDTO> getRunningTasks(TaskCenterRequest request) {
|
||||||
|
if (StringUtils.isEmpty(request.getProjectId())) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
return extTaskMapper.getRunningTasks(request);
|
return extTaskMapper.getRunningTasks(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ public class TestPlanApiCaseService {
|
||||||
if (element.getString("type").equals("HTTPSamplerProxy")) {
|
if (element.getString("type").equals("HTTPSamplerProxy")) {
|
||||||
MsHTTPSamplerProxy httpSamplerProxy = JSON.parseObject(api, MsHTTPSamplerProxy.class);
|
MsHTTPSamplerProxy httpSamplerProxy = JSON.parseObject(api, MsHTTPSamplerProxy.class);
|
||||||
httpSamplerProxy.setHashTree(list);
|
httpSamplerProxy.setHashTree(list);
|
||||||
httpSamplerProxy.setName(caseWithBLOBs.getId());
|
httpSamplerProxy.setName(planId);
|
||||||
httpSamplerProxy.setUseEnvironment(apiCase.getEnvironmentId());
|
httpSamplerProxy.setUseEnvironment(apiCase.getEnvironmentId());
|
||||||
return httpSamplerProxy;
|
return httpSamplerProxy;
|
||||||
}
|
}
|
||||||
|
@ -279,21 +279,21 @@ public class TestPlanApiCaseService {
|
||||||
MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class);
|
MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class);
|
||||||
msTCPSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
msTCPSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
||||||
msTCPSampler.setHashTree(list);
|
msTCPSampler.setHashTree(list);
|
||||||
msTCPSampler.setName(caseWithBLOBs.getId());
|
msTCPSampler.setName(planId);
|
||||||
return msTCPSampler;
|
return msTCPSampler;
|
||||||
}
|
}
|
||||||
if (element.getString("type").equals("DubboSampler")) {
|
if (element.getString("type").equals("DubboSampler")) {
|
||||||
MsDubboSampler dubboSampler = JSON.parseObject(api, MsDubboSampler.class);
|
MsDubboSampler dubboSampler = JSON.parseObject(api, MsDubboSampler.class);
|
||||||
dubboSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
dubboSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
||||||
dubboSampler.setHashTree(list);
|
dubboSampler.setHashTree(list);
|
||||||
dubboSampler.setName(caseWithBLOBs.getId());
|
dubboSampler.setName(planId);
|
||||||
return dubboSampler;
|
return dubboSampler;
|
||||||
}
|
}
|
||||||
if (element.getString("type").equals("JDBCSampler")) {
|
if (element.getString("type").equals("JDBCSampler")) {
|
||||||
MsJDBCSampler jDBCSampler = JSON.parseObject(api, MsJDBCSampler.class);
|
MsJDBCSampler jDBCSampler = JSON.parseObject(api, MsJDBCSampler.class);
|
||||||
jDBCSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
jDBCSampler.setUseEnvironment(apiCase.getEnvironmentId());
|
||||||
jDBCSampler.setHashTree(list);
|
jDBCSampler.setHashTree(list);
|
||||||
jDBCSampler.setName(caseWithBLOBs.getId());
|
jDBCSampler.setName(planId);
|
||||||
return jDBCSampler;
|
return jDBCSampler;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue