如何在REST Assured上为请求设置timout?

时间:2017-12-27 07:28:19

标签: java rest-assured

我使用REST Assured发送帖子请求。问题是它根本没有超时。 在我的情况下,服务器有时会无法访问,这会永久锁定请求。

3 个答案:

答案 0 :(得分:1)

您可以看到here。它有几种方法可以做到,请查看:

when().async().with().timeout(20, TimeUnit.SECONDS)

given().config(config().asyncConfig(withTimeout(100, TimeUnit.MILLISECONDS))).

答案 1 :(得分:1)

找到答案。我在这里发帖,希望它会帮助别人。

RestAssured.config=RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().
        setParam("http.connection.timeout",300000).
        setParam("http.socket.timeout",300000).
        setParam("http.connection-manager.timeout",300000));

答案 2 :(得分:0)

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

);