From 9139471fc80feeecdde56eb82b63c556833c77e6 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 8 May 2023 11:33:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=AE=A1=E5=88=92=E4=BC=9A=E5=81=B6=E5=8F=91=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E4=BA=BA=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1026019 --user=宋天阳 【测试跟踪】测试计划批量执行-报告执行人非当前执行人-任务中心不显示执行记录 https://www.tapd.cn/55049933/s/1369590 --- .../base/domain/TestPlanExecutionQueue.java | 5 +- .../domain/TestPlanExecutionQueueExample.java | 70 +++++++++++++++++++ .../mapper/TestPlanExecutionQueueMapper.java | 3 +- .../mapper/TestPlanExecutionQueueMapper.xml | 37 +++++++--- .../plan/service/TestPlanMessageService.java | 44 ++++++------ .../plan/service/TestPlanReportService.java | 4 ++ .../plan/service/TestPlanService.java | 9 ++- .../V12__alter_test_plan_execute_queue.sql | 8 +++ 8 files changed, 140 insertions(+), 40 deletions(-) create mode 100644 test-track/backend/src/main/resources/db/migration/2.10.0/ddl/V12__alter_test_plan_execute_queue.sql diff --git a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueue.java b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueue.java index c396ca2bc2..d8b209bb9f 100644 --- a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueue.java +++ b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueue.java @@ -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; } \ No newline at end of file diff --git a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueueExample.java b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueueExample.java index 79411fe851..6d464d6f7e 100644 --- a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueueExample.java +++ b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/TestPlanExecutionQueueExample.java @@ -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 values) { + addCriterion("execute_user in", values, "executeUser"); + return (Criteria) this; + } + + public Criteria andExecuteUserNotIn(List 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 { diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java index 20ca461c98..f29e9ed0e3 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.java @@ -28,5 +28,4 @@ public interface TestPlanExecutionQueueMapper { int updateByPrimaryKeySelective(TestPlanExecutionQueue record); int updateByPrimaryKey(TestPlanExecutionQueue record); - -} +} \ No newline at end of file diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.xml index aebee2936d..bcd2f4eb51 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/TestPlanExecutionQueueMapper.xml @@ -9,6 +9,7 @@ + @@ -69,7 +70,7 @@ - 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 @@ -188,6 +195,9 @@ num = #{record.num,jdbcType=INTEGER}, + + execute_user = #{record.executeUser,jdbcType=VARCHAR}, + @@ -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} @@ -227,6 +238,9 @@ num = #{num,jdbcType=INTEGER}, + + execute_user = #{executeUser,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -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} - + \ No newline at end of file diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java index d21a4015d0..310c545ce6 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java @@ -50,37 +50,35 @@ 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()); - //更新TestPlan状态为完成 - TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); - if (testPlan != null - && !StringUtils.equalsAny(testPlan.getStatus(), TestPlanStatus.Completed.name(), TestPlanStatus.Finished.name())) { - - testPlan.setStatus(calcTestPlanStatusWithPassRate(testPlan)); - testPlanService.editTestPlan(testPlan); - } try { - if (sendMessage && testPlan != null && StringUtils.equalsAny(report.getTriggerMode(), - ReportTriggerMode.MANUAL.name(), - ReportTriggerMode.API.name(), - ReportTriggerMode.SCHEDULE.name()) && !StringUtils.equalsIgnoreCase(report.getStatus(), ExecuteResult.TEST_PLAN_RUNNING.toString()) - ) { - //发送通知 - this.sendMessage(testPlan, report, testPlan.getProjectId()); + report = testPlanReportService.checkTestPlanReportHasErrorCase(report, testPlanReportContent); + if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) { + //更新TestPlan状态为完成 + TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); + if (testPlan != null + && !StringUtils.equalsAny(testPlan.getStatus(), TestPlanStatus.Completed.name(), TestPlanStatus.Finished.name())) { + + testPlan.setStatus(calcTestPlanStatusWithPassRate(testPlan)); + testPlanService.editTestPlan(testPlan); + } + if (sendMessage && testPlan != null && StringUtils.equalsAny(report.getTriggerMode(), + ReportTriggerMode.MANUAL.name(), + ReportTriggerMode.API.name(), + ReportTriggerMode.SCHEDULE.name()) && !StringUtils.equalsIgnoreCase(report.getStatus(), ExecuteResult.TEST_PLAN_RUNNING.toString()) + ) { + //发送通知 + this.sendMessage(testPlan, report, testPlan.getProjectId()); + } } } catch (Exception e) { - LogUtil.error(e); + LogUtil.error("检查测试计划状态出错", e); } finally { HttpHeaderUtils.clearUser(); } + } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index b510359906..aed2e40331 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -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 { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index b3fe0c5226..4b5d03fc95 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -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 { diff --git a/test-track/backend/src/main/resources/db/migration/2.10.0/ddl/V12__alter_test_plan_execute_queue.sql b/test-track/backend/src/main/resources/db/migration/2.10.0/ddl/V12__alter_test_plan_execute_queue.sql new file mode 100644 index 0000000000..9f4a8dcf6d --- /dev/null +++ b/test-track/backend/src/main/resources/db/migration/2.10.0/ddl/V12__alter_test_plan_execute_queue.sql @@ -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;