refactor(接口测试): mock增加响应延迟时间
This commit is contained in:
parent
5e8034ae51
commit
68a79b030d
|
@ -27,4 +27,7 @@ public class MockResponse implements Serializable {
|
|||
|
||||
@Schema(description = "响应请求体")
|
||||
private ResponseBody body;
|
||||
|
||||
@Schema(description = "响应延迟时间(毫秒)")
|
||||
private Long delay;
|
||||
}
|
||||
|
|
|
@ -187,6 +187,7 @@ public class MockServerService {
|
|||
int responseCode = -1;
|
||||
String useApiResponseId = null;
|
||||
|
||||
Long delay = null;
|
||||
if (config != null) {
|
||||
MockResponse mockResponse = JSON.parseObject(new String(config.getResponse()), MockResponse.class);
|
||||
// mock 响应引用的是接口自身响应内容
|
||||
|
@ -196,6 +197,7 @@ public class MockServerService {
|
|||
responseCode = mockResponse.getStatusCode();
|
||||
responseHeader = mockResponse.getHeaders();
|
||||
responseBody = mockResponse.getBody();
|
||||
delay = mockResponse.getDelay();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,6 +234,12 @@ public class MockServerService {
|
|||
}
|
||||
|
||||
if (responseBody != null) {
|
||||
if (delay != null && delay > 0) {
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
boolean isMock = config != null;
|
||||
String resourceId = config != null ? config.getId() : apiId;
|
||||
return switch (responseBody.getBodyType()) {
|
||||
|
|
Loading…
Reference in New Issue