解决异步执行线程卡住问题

This commit is contained in:
liangdaliang
2025-05-28 19:02:53 +08:00
parent a9d0f68f52
commit 75fcd51dea
4 changed files with 9 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo; import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType; import com.test.common.enums.BusinessType;
import com.test.common.utils.DateUtils; import com.test.common.utils.DateUtils;
import com.test.common.utils.SecurityUtils;
import com.test.common.utils.uuid.IdUtils; import com.test.common.utils.uuid.IdUtils;
import com.test.test.domain.TestCase; import com.test.test.domain.TestCase;
import com.test.test.domain.TestPlanCase; import com.test.test.domain.TestPlanCase;
@@ -127,6 +128,7 @@ public class TestCaseController extends BaseController {
@PostMapping("/runTestPlanCase") @PostMapping("/runTestPlanCase")
public AjaxResult runTestPlanCase(@RequestBody TestPlanCase testPlanCase) { public AjaxResult runTestPlanCase(@RequestBody TestPlanCase testPlanCase) {
String caseSid = IdUtils.simpleUUID(); String caseSid = IdUtils.simpleUUID();
testPlanCase.setExecuteBy(SecurityUtils.getUsername());
// 异步执行任务 // 异步执行任务
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
testCaseService.executeTestCaseByPlanCase(testPlanCase, jmeterHomePath, caseSid); testCaseService.executeTestCaseByPlanCase(testPlanCase, jmeterHomePath, caseSid);

View File

@@ -40,8 +40,8 @@ public class TestPlanCase extends BaseEntity
private String executeResult; private String executeResult;
/** 执行时间 */ /** 执行时间 */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date executeTime; private Date executeTime;
/** 执行人 */ /** 执行人 */

View File

@@ -229,7 +229,7 @@ public class TestCaseServiceImpl implements ITestCaseService
for (TestPlanCase input : testPlanCaseList) { for (TestPlanCase input : testPlanCaseList) {
boolean isSuccess = true; boolean isSuccess = true;
input.setExecuteTime(DateUtils.getNowDate()); input.setExecuteTime(DateUtils.getNowDate());
input.setExecuteBy(SecurityUtils.getUsername()); input.setExecuteBy(testPlanCase.getExecuteBy());
TestCase testCase = this.selectTestCaseById(input.getCaseId()); TestCase testCase = this.selectTestCaseById(input.getCaseId());
Long id = input.getCaseId(); Long id = input.getCaseId();
Map<String, String> contextResultMap = new HashMap<>(); Map<String, String> contextResultMap = new HashMap<>();
@@ -290,13 +290,14 @@ public class TestCaseServiceImpl implements ITestCaseService
} }
if (isSuccess) { if (isSuccess) {
testCaseLog.setOperDetail("成功"); testCaseLog.setOperDetail("成功");
input.setExecuteResult("成功"); input.setExecuteResult("1");
} else { } else {
testCaseLog.setOperDetail("失败"); testCaseLog.setOperDetail("失败");
input.setExecuteResult("失败"); input.setExecuteResult("2");
} }
testCaseLogMapper.insertTestCaseLog(testCaseLog); testCaseLogMapper.insertTestCaseLog(testCaseLog);
testPlanCaseMapper.updateTestPlanCase(input); testPlanCaseMapper.updateTestPlanCase(input);
System.out.println("111111111111111111111111");
} }
testPlan.setUpdateTime(DateUtils.getNowDate()); testPlan.setUpdateTime(DateUtils.getNowDate());
testPlan.setStatus("2"); testPlan.setStatus("2");

View File

@@ -39,7 +39,7 @@
<el-Table v-loading="loading" :data="list" @selection-change="handleSelectionChange"> <el-Table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
<el-table-column type="selection"/> <el-table-column type="selection"/>
<el-table-column prop="caseName" label="测试用例名称" align="center"/> <el-table-column prop="caseName" label="测试用例名称" align="center"/>
<el-table-column prop="executeResult" label="执行结果" align="center"/> <el-table-column prop="executeResult" label="执行结果" :formatter="row => ['未执行', '成功', '失败'][row.executeResult]" align="center"/>
<el-table-column prop="createBy" label="创建人" align="center"/> <el-table-column prop="createBy" label="创建人" align="center"/>
<el-table-column prop="executeBy" label="最近执行人" align="center"/> <el-table-column prop="executeBy" label="最近执行人" align="center"/>
<el-table-column prop="executeTime" label="最近执行时间" align="center"/> <el-table-column prop="executeTime" label="最近执行时间" align="center"/>