load test status

This commit is contained in:
Captain.B 2020-04-01 16:23:51 +08:00
parent 1841fcfa19
commit 16168b24b9
3 changed files with 22 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.testplan.*;
@ -85,7 +86,10 @@ public class LoadTestController {
@PostMapping("/run")
public void run(@RequestBody RunTestPlanRequest request) {
loadTestService.run(request);
boolean started = loadTestService.run(request);
if (!started) {
MSException.throwException("Start engine error, please check log.");
}
}
@GetMapping("/file/metadata/{testId}")

View File

@ -89,7 +89,7 @@ public class DockerTestEngine extends AbstractEngine {
for (int i = 0; i < containerList.size(); i++) {
HashMap h = (HashMap) containerList.get(i);
if (StringUtils.equals((String) h.get("State"), "running")) {
MSException.throwException("the test is running!");
MSException.throwException("The test is running!");
}
}

View File

@ -14,6 +14,7 @@ import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineFactory;
import io.metersphere.i18n.Translator;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -163,12 +164,13 @@ public class LoadTestService {
return request.getId();
}
public void run(RunTestPlanRequest request) {
public boolean run(RunTestPlanRequest request) {
final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId());
if (loadTest == null) {
MSException.throwException(Translator.get("run_load_test_not_found") + request.getId());
}
if (TestStatus.Running.name().equals(loadTest.getStatus())) {
if (StringUtils.equalsAny(loadTest.getStatus(), TestStatus.Running.name(), TestStatus.Starting.name())) {
MSException.throwException(Translator.get("load_test_is_running"));
}
@ -178,14 +180,21 @@ public class LoadTestService {
if (engine == null) {
MSException.throwException(String.format("Test cannot be runtest ID%s", request.getId()));
}
return startEngine(loadTest, engine);
// todo通过调用stop方法能够停止正在运行的engine但是如果部署了多个backend实例页面发送的停止请求如何定位到具体的engine
}
private boolean startEngine(LoadTestWithBLOBs loadTest, Engine engine) {
LoadTestReportWithBLOBs testReport = new LoadTestReportWithBLOBs();
testReport.setId(engine.getReportId());
testReport.setCreateTime(engine.getStartTime());
testReport.setUpdateTime(engine.getStartTime());
testReport.setTestId(loadTest.getId());
testReport.setName(loadTest.getName());
// 启动测试
boolean started = true;
try {
engine.start();
// 标记running状态
@ -199,6 +208,9 @@ public class LoadTestService {
extLoadTestReportMapper.appendLine(testReport.getId(), "\n");
} catch (Exception e) {
LogUtil.error(e);
started = false;
loadTest.setStatus(TestStatus.Error.name());
loadTestMapper.updateByPrimaryKeySelective(loadTest);
//
@ -206,7 +218,7 @@ public class LoadTestService {
testReport.setDescription(e.getMessage());
loadTestReportMapper.insertSelective(testReport);
}
// todo通过调用stop方法能够停止正在运行的engine但是如果部署了多个backend实例页面发送的停止请求如何定位到具体的engine
return started;
}
public List<LoadTestDTO> recentTestPlans(QueryTestPlanRequest request) {