fix(测试跟踪): 修复批量执行测试计划会偶发执行人错误的问题
--bug=1026019 --user=宋天阳 【测试跟踪】测试计划批量执行-报告执行人非当前执行人-任务中心不显示执行记录 https://www.tapd.cn/55049933/s/1369590
This commit is contained in:
parent
c266e9522a
commit
9139471fc8
|
@ -1,8 +1,7 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TestPlanExecutionQueue implements Serializable {
|
||||
|
@ -20,5 +19,7 @@ public class TestPlanExecutionQueue implements Serializable {
|
|||
|
||||
private Integer num;
|
||||
|
||||
private String executeUser;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -573,6 +573,76 @@ public class TestPlanExecutionQueueExample {
|
|||
addCriterion("num not between", value1, value2, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserIsNull() {
|
||||
addCriterion("execute_user is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserIsNotNull() {
|
||||
addCriterion("execute_user is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserEqualTo(String value) {
|
||||
addCriterion("execute_user =", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserNotEqualTo(String value) {
|
||||
addCriterion("execute_user <>", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserGreaterThan(String value) {
|
||||
addCriterion("execute_user >", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("execute_user >=", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserLessThan(String value) {
|
||||
addCriterion("execute_user <", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserLessThanOrEqualTo(String value) {
|
||||
addCriterion("execute_user <=", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserLike(String value) {
|
||||
addCriterion("execute_user like", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserNotLike(String value) {
|
||||
addCriterion("execute_user not like", value, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserIn(List<String> values) {
|
||||
addCriterion("execute_user in", values, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserNotIn(List<String> values) {
|
||||
addCriterion("execute_user not in", values, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserBetween(String value1, String value2) {
|
||||
addCriterion("execute_user between", value1, value2, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andExecuteUserNotBetween(String value1, String value2) {
|
||||
addCriterion("execute_user not between", value1, value2, "executeUser");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
|
|
@ -28,5 +28,4 @@ public interface TestPlanExecutionQueueMapper {
|
|||
int updateByPrimaryKeySelective(TestPlanExecutionQueue record);
|
||||
|
||||
int updateByPrimaryKey(TestPlanExecutionQueue record);
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
<result column="test_plan_id" jdbcType="VARCHAR" property="testPlanId" />
|
||||
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
<result column="num" jdbcType="INTEGER" property="num" />
|
||||
<result column="execute_user" jdbcType="VARCHAR" property="executeUser" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
|
@ -69,7 +70,7 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, report_id, run_mode, create_time, test_plan_id, resource_id, num
|
||||
id, report_id, run_mode, create_time, test_plan_id, resource_id, num, execute_user
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.base.domain.TestPlanExecutionQueueExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -104,10 +105,10 @@
|
|||
<insert id="insert" parameterType="io.metersphere.base.domain.TestPlanExecutionQueue">
|
||||
insert into test_plan_execution_queue (id, report_id, run_mode,
|
||||
create_time, test_plan_id, resource_id,
|
||||
num)
|
||||
num, execute_user)
|
||||
values (#{id,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{runMode,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT}, #{testPlanId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
|
||||
#{num,jdbcType=INTEGER})
|
||||
#{num,jdbcType=INTEGER}, #{executeUser,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlanExecutionQueue">
|
||||
insert into test_plan_execution_queue
|
||||
|
@ -133,6 +134,9 @@
|
|||
<if test="num != null">
|
||||
num,
|
||||
</if>
|
||||
<if test="executeUser != null">
|
||||
execute_user,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
|
@ -156,6 +160,9 @@
|
|||
<if test="num != null">
|
||||
#{num,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="executeUser != null">
|
||||
#{executeUser,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.TestPlanExecutionQueueExample" resultType="java.lang.Long">
|
||||
|
@ -188,6 +195,9 @@
|
|||
<if test="record.num != null">
|
||||
num = #{record.num,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.executeUser != null">
|
||||
execute_user = #{record.executeUser,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
|
@ -201,7 +211,8 @@
|
|||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
test_plan_id = #{record.testPlanId,jdbcType=VARCHAR},
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
num = #{record.num,jdbcType=INTEGER}
|
||||
num = #{record.num,jdbcType=INTEGER},
|
||||
execute_user = #{record.executeUser,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
|
@ -227,6 +238,9 @@
|
|||
<if test="num != null">
|
||||
num = #{num,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="executeUser != null">
|
||||
execute_user = #{executeUser,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
@ -237,7 +251,8 @@
|
|||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
test_plan_id = #{testPlanId,jdbcType=VARCHAR},
|
||||
resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
num = #{num,jdbcType=INTEGER}
|
||||
num = #{num,jdbcType=INTEGER},
|
||||
execute_user = #{executeUser,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -50,15 +50,12 @@ public class TestPlanMessageService {
|
|||
|
||||
@Async
|
||||
public void checkTestPlanStatusAndSendMessage(TestPlanReport report, TestPlanReportContentWithBLOBs testPlanReportContent, boolean sendMessage) {
|
||||
if (report == null) {
|
||||
return;
|
||||
}
|
||||
if (testPlanReportContent != null) {
|
||||
report = testPlanReportService.checkTestPlanReportHasErrorCase(report, testPlanReportContent);
|
||||
}
|
||||
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) {
|
||||
if (report != null && testPlanReportContent != null) {
|
||||
// 异步发送通知需要指定调用其他服务的user
|
||||
HttpHeaderUtils.runAsUser(report.getCreator());
|
||||
try {
|
||||
report = testPlanReportService.checkTestPlanReportHasErrorCase(report, testPlanReportContent);
|
||||
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) {
|
||||
//更新TestPlan状态为完成
|
||||
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId());
|
||||
if (testPlan != null
|
||||
|
@ -67,7 +64,6 @@ public class TestPlanMessageService {
|
|||
testPlan.setStatus(calcTestPlanStatusWithPassRate(testPlan));
|
||||
testPlanService.editTestPlan(testPlan);
|
||||
}
|
||||
try {
|
||||
if (sendMessage && testPlan != null && StringUtils.equalsAny(report.getTriggerMode(),
|
||||
ReportTriggerMode.MANUAL.name(),
|
||||
ReportTriggerMode.API.name(),
|
||||
|
@ -76,11 +72,13 @@ public class TestPlanMessageService {
|
|||
//发送通知
|
||||
this.sendMessage(testPlan, report, testPlan.getProjectId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
LogUtil.error("检查测试计划状态出错", e);
|
||||
} finally {
|
||||
HttpHeaderUtils.clearUser();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -683,6 +683,10 @@ public class TestPlanReportService {
|
|||
Map jsonObject = JSON.parseMap(testPlan.getRunModeConfig());
|
||||
TestPlanRequestUtil.changeStringToBoolean(jsonObject);
|
||||
TestPlanRunRequest runRequest = JSON.parseObject(JSON.toJSONString(jsonObject), TestPlanRunRequest.class);
|
||||
if (StringUtils.isNotBlank(testPlanExecutionQueue.getExecuteUser())) {
|
||||
runRequest.setUserId(testPlanExecutionQueue.getExecuteUser());
|
||||
}
|
||||
runRequest.setTestPlanId(testPlanExecutionQueue.getTestPlanId());
|
||||
runRequest.setReportId(testPlanExecutionQueue.getReportId());
|
||||
runRequest.setTestPlanId(testPlan.getId());
|
||||
try {
|
||||
|
|
|
@ -474,8 +474,7 @@ public class TestPlanService {
|
|||
}
|
||||
});
|
||||
testPlan.setTotal(testPlan.getTotal() + execResults.size());
|
||||
} catch (MSException e) {
|
||||
LogUtil.error(e);
|
||||
} catch (MSException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -527,6 +526,7 @@ public class TestPlanService {
|
|||
|
||||
/**
|
||||
* 异步将测试计划的状态置为已结束
|
||||
*
|
||||
* @param changeToFinishedIds
|
||||
*/
|
||||
@Async
|
||||
|
@ -2159,6 +2159,7 @@ public class TestPlanService {
|
|||
executionQueue.setRunMode(request.getMode());
|
||||
executionQueue.setResourceId(resourceId);
|
||||
executionQueue.setNum(nextNum[0]);
|
||||
executionQueue.setExecuteUser(request.getUserId());
|
||||
nextNum[0]++;
|
||||
planExecutionQueues.add(executionQueue);
|
||||
});
|
||||
|
@ -2174,6 +2175,10 @@ public class TestPlanService {
|
|||
Map jsonObject = JSON.parseMap(testPlan.getRunModeConfig());
|
||||
TestPlanRequestUtil.changeStringToBoolean(jsonObject);
|
||||
TestPlanRunRequest runRequest = JSON.parseObject(JSON.toJSONString(jsonObject), TestPlanRunRequest.class);
|
||||
if (StringUtils.isNotBlank(planExecutionQueue.getExecuteUser())) {
|
||||
runRequest.setUserId(planExecutionQueue.getExecuteUser());
|
||||
}
|
||||
runRequest.setTestPlanId(planExecutionQueue.getTestPlanId());
|
||||
runRequest.setReportId(planExecutionQueue.getReportId());
|
||||
runPlan(runRequest);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
SET SESSION innodb_lock_wait_timeout = 7200;
|
||||
|
||||
|
||||
-- 队列增加执行人
|
||||
ALTER TABLE test_plan_execution_queue
|
||||
ADD COLUMN `execute_user` VARCHAR(50);
|
||||
|
||||
SET SESSION innodb_lock_wait_timeout = DEFAULT;
|
Loading…
Reference in New Issue