From 6fb68840938afb7e65af187772674b3706bf8ea1 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 9 Nov 2021 18:49:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98=E5=B9=B6?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BC=98=E5=8C=96=E9=9C=80=E6=B1=82=20#10038?= =?UTF-8?q?13=20--story=3D1003813=20--user=3D=E8=B5=B5=E5=8B=87=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=8A=E4=BC=A0=20csv=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20https://www.tapd.cn/55049933/s/1065761?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/jmeter/FixedTask.java | 4 ++-- .../api/service/ApiAutomationService.java | 23 +++++++------------ .../api/service/ApiScenarioReportService.java | 13 ++++++++--- .../scenario/variable/CsvFileUpload.vue | 10 ++++---- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/jmeter/FixedTask.java b/backend/src/main/java/io/metersphere/api/jmeter/FixedTask.java index 4aa21da966..d11cb35764 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/FixedTask.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/FixedTask.java @@ -35,8 +35,8 @@ public class FixedTask { ReportCounter counter = MessageCache.cache.get(key); LogUtil.info("集成报告:【" + key + "】总执行场景:【" + counter.getReportIds().size() + "】已经执行完成场景:【" + counter.getCompletedIds().size() + "】"); List filterList = counter.getReportIds().stream().filter(t -> !counter.getCompletedIds().contains(t)).collect(Collectors.toList()); - LogUtil.info("剩余要执行的报告" + JSON.toJSONString(filterList)); + LogUtil.debug("剩余要执行的报告" + JSON.toJSONString(filterList)); // 合并 if (counter.getCompletedIds().size() >= counter.getReportIds().size()) { scenarioReportService.margeReport(key, counter.getReportIds()); @@ -55,7 +55,7 @@ public class FixedTask { // 资源池中已经没有执行的请求了 int runningCount = scenarioReportService.get(key, counter); if (runningCount == 0) { - LogUtil.info("发生未知异常,进行资源合并,请检查资源池是否正常运行"); + LogUtil.error("发生未知异常,进行资源合并,请检查资源池是否正常运行"); scenarioReportService.margeReport(key, counter.getReportIds()); guardTask.remove(key); MessageCache.cache.remove(key); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 8a6156fe3b..c616e57a56 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1361,23 +1361,16 @@ public class ApiAutomationService { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); // 开始并发执行 - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - for (String reportId : executeQueue.keySet()) { - //存储报告 - APIScenarioReportResult report = executeQueue.get(reportId).getReport(); - batchMapper.insert(report); - // 增加一个本地锁,防止并发找不到资源 - MessageCache.scenarioExecResourceLock.put(reportId, report); - } - sqlSession.flushStatements(); - sqlSession.commit(); - } - }); - thread.start(); + for (String reportId : executeQueue.keySet()) { + //存储报告 + APIScenarioReportResult report = executeQueue.get(reportId).getReport(); + batchMapper.insert(report); + MessageCache.scenarioExecResourceLock.put(reportId, report); + } + sqlSession.flushStatements(); for (String reportId : executeQueue.keySet()) { + // 增加一个本地锁,防止并发找不到资源 if (request.getConfig() != null && StringUtils.isNotEmpty(request.getConfig().getResourcePoolId())) { String testPlanScenarioId = ""; if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(executeQueue.get(reportId).getTestId())) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index f64add9a40..fa2a494469 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -519,11 +519,18 @@ public class ApiScenarioReportService { ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample(); scenarioReportExample.createCriteria().andScenarioIdIn(list); List reportList = apiScenarioReportMapper.selectByExample(scenarioReportExample); - list.forEach(item ->{ - if(MessageCache.scenarioExecResourceLock.containsKey(item)) { + + if (CollectionUtils.isEmpty(reportList)) { + ApiScenarioReportExample example = new ApiScenarioReportExample(); + example.createCriteria().andIdIn(list); + reportList = apiScenarioReportMapper.selectByExample(example); + } + + for (String item : list) { + if (MessageCache.scenarioExecResourceLock.containsKey(item)) { reportList.add(MessageCache.scenarioExecResourceLock.get(item)); } - }); + } for (ApiScenarioReport report : reportList) { report.setStatus("Error"); apiScenarioReportMapper.updateByPrimaryKey(report); diff --git a/frontend/src/business/components/api/automation/scenario/variable/CsvFileUpload.vue b/frontend/src/business/components/api/automation/scenario/variable/CsvFileUpload.vue index 8c0c50e238..9f2cd2faea 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/CsvFileUpload.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/CsvFileUpload.vue @@ -33,6 +33,8 @@