如何在 REST Assured 中设置请求超时?
How to set timout for request on REST Assured?
我正在使用 REST Assured 发送 post 请求。问题是它根本没有超时。
在我的例子中,服务器有时无法访问,这会永远锁定请求。
Rest-Assured 基于 apache httpclient:
RestAssured.config = RestAssured.config().httpClient(httpClientConfig()
.setParam(ClientPNames.CONN_MANAGER_TIMEOUT, Long.valueOf(DEFAULT_TIMEOUT_IN_MS)) // HttpConnectionManager connection return time
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT_IN_MS) // Remote host connection time
.setParam(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT_IN_MS) // Remote host response time
);
可以看到here。它有几种方法可以做到这一点,检查这个:
when().async().with().timeout(20, TimeUnit.SECONDS)
或
given().config(config().asyncConfig(withTimeout(100, TimeUnit.MILLISECONDS))).
找到答案。我把它贴在这里,希望它能帮助别人。
RestAssured.config=RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().
setParam("http.connection.timeout",300000).
setParam("http.socket.timeout",300000).
setParam("http.connection-manager.timeout",300000));
我正在使用 REST Assured 发送 post 请求。问题是它根本没有超时。 在我的例子中,服务器有时无法访问,这会永远锁定请求。
Rest-Assured 基于 apache httpclient:
RestAssured.config = RestAssured.config().httpClient(httpClientConfig()
.setParam(ClientPNames.CONN_MANAGER_TIMEOUT, Long.valueOf(DEFAULT_TIMEOUT_IN_MS)) // HttpConnectionManager connection return time
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT_IN_MS) // Remote host connection time
.setParam(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT_IN_MS) // Remote host response time
);
可以看到here。它有几种方法可以做到这一点,检查这个:
when().async().with().timeout(20, TimeUnit.SECONDS)
或
given().config(config().asyncConfig(withTimeout(100, TimeUnit.MILLISECONDS))).
找到答案。我把它贴在这里,希望它能帮助别人。
RestAssured.config=RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().
setParam("http.connection.timeout",300000).
setParam("http.socket.timeout",300000).
setParam("http.connection-manager.timeout",300000));