Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
wan92hen committed Apr 27, 2021
2 parents 4e7fc5b + c1f14a8 commit cf6c02e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/main/java/io/metersphere/MeterSphereBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
public void getTestStepsByModular(MeterSphereClient meterSphereClient, List<TestCaseDTO> modelList, String projectId, String _environmentId, String testPlanId) {
final AtomicBoolean success = new AtomicBoolean(false);
JSON.toJSONString(modelList);
/*
log("testList=" + "[" + JSON.toJSONString(modelList) + "]");
*/
final ExecutorService testThreadPool = Executors.newFixedThreadPool(modelList.size());
final CountDownLatch countDownLatch = new CountDownLatch(modelList.size());
if (modelList.size() > 0) {
Expand All @@ -129,7 +126,6 @@ public void run() {
if (num == 0) {
success.set(true);
}

} catch (Exception e) {
log(e.getMessage());
} finally {
Expand All @@ -146,7 +142,7 @@ public void run() {
public void run() {
try {
int num = 1;
num = num * runPerformTest(meterSphereClient, c, c.getId());
num = num * runPerformTest(meterSphereClient, c, c.getId(), testPlanId);
if (num == 0) {
success.set(true);
}
Expand Down Expand Up @@ -225,7 +221,7 @@ public void run() {
}

public void getTestStepsBySingle(MeterSphereClient meterSphereClient, List<TestCaseDTO> testCaseIds, String environmentId, String projectId) {
log("testList=" + "[" + JSON.toJSONString(testCaseIds) + "]");
//log("testList=" + "[" + JSON.toJSONString(testCaseIds) + "]");
log("testCaseId=" + "[" + testCaseId + "]");
log("environmentId=" + "[" + environmentId + "]");
boolean flag = true;
Expand All @@ -243,7 +239,7 @@ public void getTestStepsBySingle(MeterSphereClient meterSphereClient, List<TestC
}
}
if (StringUtils.equals(Results.PERFORMANCE, c.getType())) {
int num = runPerformTest(meterSphereClient, c, testCaseId);
int num = runPerformTest(meterSphereClient, c, testCaseId, "");
if (num == 0) {
flag = false;
}
Expand Down Expand Up @@ -290,7 +286,7 @@ public int runApiTest(MeterSphereClient meterSphereClient, TestCaseDTO c, String
String apiTestState = "";
while (state) {
apiTestState = meterSphereClient.getApiTestState(reportId);
log("接口测试" + c.getName() + "执行状态:" + apiTestState);
log("接口测试[" + c.getName() + "]执行状态:" + apiTestState);
if (apiTestState.equalsIgnoreCase(Results.SUCCESS)) {
state = false;
log("点击链接进入" + c.getName() + "测试报告页面:" + url + "/#/api/report/view/" + reportId.replace("\"", ""));
Expand All @@ -311,12 +307,12 @@ public int runApiTest(MeterSphereClient meterSphereClient, TestCaseDTO c, String
return num;
}

public int runPerformTest(MeterSphereClient meterSphereClient, TestCaseDTO c, String id) {
public int runPerformTest(MeterSphereClient meterSphereClient, TestCaseDTO c, String id, String testPlanId) {
String url = meterSphereClient.getBaseInfo();
String reportId = "";
int num = 1;
try {
reportId = meterSphereClient.runPerformanceTest(id);
reportId = meterSphereClient.runPerformanceTest(id, testPlanId);
} catch (Exception e) {
num = 0;
log(c.getName() + "发生异常:" + e.getMessage());
Expand All @@ -326,12 +322,16 @@ public int runPerformTest(MeterSphereClient meterSphereClient, TestCaseDTO c, St
String pfmTestState = "";
while (state) {
pfmTestState = meterSphereClient.getPerformanceTestState(id);
log("性能测试" + c.getName() + "执行状态:" + pfmTestState);
log("性能测试[" + c.getName() + "]执行状态:" + pfmTestState);
if (pfmTestState.equalsIgnoreCase(Results.COMPLETED)) {
//更新测试计划下性能测试状态
meterSphereClient.updateStateLoad(testPlanId, id, "success");
state = false;
log("点击链接进入" + c.getName() + "测试报告页面: " + url + "/#/performance/report/view/" + reportId.replace("\"", ""));
meterSphereClient.changeState(id, Results.PASS);
} else if (pfmTestState.equalsIgnoreCase(Results.ERROR)) {
//更新测试计划下性能测试状态
meterSphereClient.updateStateLoad(testPlanId, id, "Error");
state = false;
num = 0;
log("点击链接进入" + c.getName() + "测试报告页面: " + url + "/#/performance/report/view/" + reportId.replace("\"", ""));
Expand Down Expand Up @@ -361,7 +361,7 @@ public int runScenario(MeterSphereClient meterSphereClient, TestCaseDTO c, Strin
String apiTestState = "";
while (state) {
apiTestState = meterSphereClient.getApiScenario(reportId);
log("场景测试" + c.getName() + "执行状态:" + apiTestState);
log("场景测试[" + c.getName() + "]执行状态:" + apiTestState);
if (apiTestState.equalsIgnoreCase(Results.SUCCESS)) {
state = false;
log("点击链接进入" + c.getName() + "测试报告页面: " + url + "/#/api/automation/report/view/" + reportId.replace("\"", ""));
Expand Down Expand Up @@ -394,7 +394,7 @@ public int runDefinition(MeterSphereClient meterSphereClient, TestCaseDTO c, Str
String status = "";
while (state) {
status = meterSphereClient.getApiTestCaseReport(c.getId(), runMode);
log("测试用例" + c.getName() + "执行状态:" + status);
log("测试用例[" + c.getName() + "]执行状态:" + status);
if (status.replace("\"", "").equalsIgnoreCase("success")) {
state = false;
} else if (status.replace("\"", "").equalsIgnoreCase("error")) {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/io/metersphere/client/MeterSphereClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,27 @@ public String getApiTestCaseReport(String id, String type) {

}

public String runPerformanceTest(String testCaseId) {
public String runPerformanceTest(String testCaseId, String testPlanId) {
HashMap<String, Object> params = new HashMap<>();
params.put("id", testCaseId);
params.put("testPlanLoadId", testCaseId);
params.put("triggerMode", "API");
ResultHolder result = call(ApiUrlConstants.PERFORMANCE_RUN, RequestMethod.POST, params);
ResultHolder result;
result = call(ApiUrlConstants.PERFORMANCE_RUN, RequestMethod.POST, params);
String listJson = JSON.toJSONString(result.getData());
return listJson.replace('"', ' ').trim();
}

public void updateStateLoad(String testPlanId, String testCaseId, String state) {
HashMap<String, Object> params = new HashMap<>();
params.put("testPlanId", testPlanId);
params.put("loadCaseId", testCaseId);
params.put("status", state);
ResultHolder result;
result = call(ApiUrlConstants.PERFORMANCE_RUN_TEST_PLAN_STATE, RequestMethod.POST, params);
JSON.toJSONString(result.getData());
}

public String getApiTestState(String reportId) {
String newReportId = reportId.replace("\"", "");
ResultHolder result = call(ApiUrlConstants.API_GET + "/" + newReportId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class ApiUrlConstants {
public static final String TEST_PLAN_CASE_LIST = "/test/plan/case/list/node";//模块下测试用例
public static final String _TEST_PLAN_CASE_LIST_ = "/test/plan/case/list/node/all";//模块下测试用例
public static final String _TEST_PLAN_CASE_LIST = "/test/plan/case/list";//计划下测试用例
public static final String PERFORMANCE_RUN = "/performance/run";//性能测试
public static final String PERFORMANCE_RUN = "/performance/run";//性能测试单个
public static final String PERFORMANCE_RUN_TEST_PLAN = "/test/plan/load/case/run";//性能测试测试计划下
public static final String PERFORMANCE_RUN_TEST_PLAN_STATE = "/test/plan/load/case/update/api";//性能测试测试计划下状态修改
public static final String API_RUN = "/api/run";//api测试
public static final String API_GET = "/api/report/get";//API测试报告(特定)
public static final String PERFORMANCE_GET = "/performance/state/get";//性能测试测试报告(特定)
Expand Down

0 comments on commit cf6c02e

Please sign in to comment.