Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
4069654f7d
|
@ -9,4 +9,5 @@ public interface ExtTestPlanLoadCaseMapper {
|
|||
|
||||
List<String> selectIdsNotInPlan(@Param("projectId") String projectId, @Param("planId") String planId);
|
||||
List<TestPlanLoadCaseDTO> selectTestPlanLoadCaseList(@Param("planId") String planId, @Param("projectId") String projectId);
|
||||
void updateCaseStatus(@Param("reportId") String reportId, @Param("status") String status);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper">
|
||||
<update id="updateCaseStatus">
|
||||
update test_plan_load_case tplc set status = #{status} where tplc.load_report_id = #{reportId}
|
||||
</update>
|
||||
|
||||
<select id="selectIdsNotInPlan" resultType="java.lang.String">
|
||||
select load_test.id
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum ReportTriggerMode {
|
||||
MANUAL, SCHEDULE, API
|
||||
MANUAL,
|
||||
SCHEDULE,
|
||||
API,
|
||||
/**
|
||||
* 性能测试用例执行触发报告
|
||||
*/
|
||||
CASE
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package io.metersphere.track.service;
|
||||
|
||||
import io.metersphere.base.domain.LoadTestReport;
|
||||
import io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.consumer.LoadTestFinishEvent;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class LoadReportStatusEvent implements LoadTestFinishEvent {
|
||||
|
||||
@Resource
|
||||
private ExtTestPlanLoadCaseMapper extTestPlanLoadCaseMapper;
|
||||
|
||||
private void updateLoadCaseStatus(LoadTestReport loadTestReport) {
|
||||
String reportId = loadTestReport.getId();
|
||||
String status = loadTestReport.getStatus();
|
||||
if (StringUtils.isNotBlank(reportId)) {
|
||||
String result = "";
|
||||
if (StringUtils.equals(PerformanceTestStatus.Error.name(), status)) {
|
||||
result = "error";
|
||||
}
|
||||
if (StringUtils.equals(PerformanceTestStatus.Completed.name(), status)) {
|
||||
result = "success";
|
||||
}
|
||||
extTestPlanLoadCaseMapper.updateCaseStatus(reportId, result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LoadTestReport loadTestReport) {
|
||||
if (StringUtils.equals(ReportTriggerMode.CASE.name(), loadTestReport.getTriggerMode())) {
|
||||
if (StringUtils.equalsAny(loadTestReport.getStatus(),
|
||||
PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
|
||||
updateLoadCaseStatus(loadTestReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package io.metersphere.track.service;
|
||||
|
||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||
import io.metersphere.base.domain.TestPlanLoadCase;
|
||||
import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||
import io.metersphere.base.mapper.TestPlanLoadCaseMapper;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Component
|
||||
public class LoadReportStatusTask {
|
||||
@Resource
|
||||
private LoadTestReportMapper loadTestReportMapper;
|
||||
@Resource
|
||||
private TestPlanLoadCaseMapper testPlanLoadCaseMapper;
|
||||
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
|
||||
private boolean isRunning = false;
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
public void registerReportIsEndTask(String id, String reportId) {
|
||||
isRunning = true;
|
||||
// todo 手动创建线程池
|
||||
executorService.submit(() -> {
|
||||
while (isRunning) {
|
||||
LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId);
|
||||
if (StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
|
||||
updateLoadCaseStatus(id, report.getStatus());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
//查询定时任务是否关闭
|
||||
Thread.sleep(1000 * 10);// 检查 loadtest 的状态
|
||||
} catch (InterruptedException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateLoadCaseStatus(String testPlanLoadCaseId, String status) {
|
||||
TestPlanLoadCase testPlanLoadCase = new TestPlanLoadCase();
|
||||
testPlanLoadCase.setId(testPlanLoadCaseId);
|
||||
String result = "";
|
||||
if (StringUtils.equals(PerformanceTestStatus.Error.name(), status)) {
|
||||
result = "error";
|
||||
}
|
||||
if (StringUtils.equals(PerformanceTestStatus.Completed.name(), status)) {
|
||||
result = "success";
|
||||
}
|
||||
testPlanLoadCase.setStatus(result);
|
||||
testPlanLoadCaseMapper.updateByPrimaryKeySelective(testPlanLoadCase);
|
||||
}
|
||||
}
|
|
@ -40,8 +40,6 @@ public class TestPlanLoadCaseService {
|
|||
private LoadTestReportMapper loadTestReportMapper;
|
||||
@Resource
|
||||
private LoadTestMapper loadTestMapper;
|
||||
@Resource
|
||||
private LoadReportStatusTask loadReportStatusTask;
|
||||
|
||||
public List<LoadTest> relevanceList(LoadCaseRequest request) {
|
||||
List<String> ids = extTestPlanLoadCaseMapper.selectIdsNotInPlan(request.getProjectId(), request.getTestPlanId());
|
||||
|
@ -85,7 +83,6 @@ public class TestPlanLoadCaseService {
|
|||
testPlanLoadCase.setId(request.getTestPlanLoadId());
|
||||
testPlanLoadCase.setLoadReportId(reportId);
|
||||
testPlanLoadCaseMapper.updateByPrimaryKeySelective(testPlanLoadCase);
|
||||
loadReportStatusTask.registerReportIsEndTask(request.getTestPlanLoadId(), reportId);
|
||||
return reportId;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<span v-if="triggerMode === 'MANUAL'">{{$t('commons.trigger_mode.manual')}}</span>
|
||||
<span v-if="triggerMode === 'SCHEDULE'">{{$t('commons.trigger_mode.schedule')}}</span>
|
||||
<span v-if="triggerMode === 'API'">{{$t('commons.trigger_mode.api')}}</span>
|
||||
<span v-if="triggerMode === 'CASE'">用例触发</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ export default {
|
|||
triggerFilters: [
|
||||
{text: this.$t('commons.trigger_mode.manual'), value: 'MANUAL'},
|
||||
{text: this.$t('commons.trigger_mode.schedule'), value: 'SCHEDULE'},
|
||||
{text: this.$t('commons.trigger_mode.api'), value: 'API'}
|
||||
{text: this.$t('commons.trigger_mode.api'), value: 'API'},
|
||||
],
|
||||
buttons: [
|
||||
{
|
||||
|
|
|
@ -261,7 +261,7 @@ export default {
|
|||
this.$post('/test/plan/load/case/run', {
|
||||
id: loadCase.loadCaseId,
|
||||
testPlanLoadId: loadCase.id,
|
||||
triggerMode: 'MANUAL'
|
||||
triggerMode: 'CASE'
|
||||
}).then(() => {
|
||||
this.$notify({
|
||||
title: loadCase.caseName,
|
||||
|
@ -324,6 +324,7 @@ export default {
|
|||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
console.log('beforeDestroy')
|
||||
this.cancelRefresh();
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue