Default timeout for all calls

5,971 views
Skip to first unread message

Lalith Choudary

unread,
Aug 14, 2014, 2:23:54 PM8/14/14
to rest-a...@googlegroups.com
Hello, This is my first post in this group. So please excuse me if I am not following any set rules. We are validating Rest Assured as functional test automation tool. So far it is going good and heading in right direction.

Is there is a way to set default timeout for all calls in a test suite? With our previous automation tool we observed once in a while test is stuck waiting for a response indefinitely. I am using Rest Assured with JUnit and maven.

Appreciate your thoughts.

-thanks,
Lalith

Johan Haleby

unread,
Aug 15, 2014, 2:45:09 AM8/15/14
to rest-a...@googlegroups.com
Hi, 

Good question. The easiest way that I can think of is to just to annotate the test method with a timeout (for example @Test(timeout = 500)) if you're using JUnit. Otherwise I'm pretty sure that there's a way to configure the underlying HTTP Client not to wait forever. You can google this and then hopefully use the HTTPClientConfig to apply the required properties. I would be interested to know your solution if you find one.

Regards,
/Johan


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lalith Choudary

unread,
Aug 15, 2014, 2:02:44 PM8/15/14
to rest-a...@googlegroups.com
Thank you for the reply Johan.

Here is what I have so far

        HttpClientConfig clientConfig = CONFIG.getHttpClientConfig();
        clientConfig.setParam("CONNECTION_MANAGER_TIMEOUT", 5000);
        System.out.println("config params = " + clientConfig.params().toString());
        RestAssuredConfig config = CONFIG.httpClient(clientConfig);

output:
config params = {http.protocol.cookie-datepatterns=[EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd MMM yyyy HH:mm:ss z], http.protocol.cookie-policy=ignoreCookies}

It doesnt seem to apply new param that was set. Tried to search documentation for valid params but so far did not find. Still continuing research.

Johan Haleby

unread,
Aug 15, 2014, 3:12:08 PM8/15/14
to rest-a...@googlegroups.com
The configuration is immutable (which I regret in hindsight) so you need to use it like this (the way you presented will not work):

RestAssuredConfig config = RestAssured.config().httpClient(httpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 5000));

/Johan

Lalith Choudary

unread,
Aug 16, 2014, 11:52:57 AM8/16/14
to rest-a...@googlegroups.com
aah i see. After further investigation seems like it was a bug in previous automation tool. Rest Assured seems to properly handle gateway timeouts and terminating connections. Thank you for the response Johan.

-Lalith

Johan Haleby

unread,
Aug 16, 2014, 12:56:57 PM8/16/14
to rest-a...@googlegroups.com
No problem, glad you got it working.

80Vikram

unread,
Feb 10, 2017, 6:14:43 AM2/10/17
to REST assured
Hi Johan,

I declared below at start of class


RestAssuredConfig config = RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 3000));


will this gets applied to all the test methods in that class ?

Thanks,
Vikram

Johan Haleby

unread,
Feb 10, 2017, 6:23:57 AM2/10/17
to rest-a...@googlegroups.com
No, you would have to use:

RestAssured.config = RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 3000));

But this will apply it to ALL tests. But you could apply it in a static setup method and call RestAssured.reset() in a static teardown.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

80Vikram

unread,
Feb 10, 2017, 8:27:56 AM2/10/17
to REST assured
Hi Johan,

RestAssuredConfig.config is giving compilation error "config cannot be resolved or is not a field"

I'm using latest version of RA.

Thanks,
Vikram

Johan Haleby

unread,
Feb 10, 2017, 8:34:26 AM2/10/17
to rest-a...@googlegroups.com
I never said you should write "RestAssuredConfig.config". Please read my previous reply again more carefully.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

80Vikram

unread,
Feb 10, 2017, 8:43:12 AM2/10/17
to REST assured
oops sorry my bad.

Thanks for your time.

Regards,
Vikram

Sumit Bhardwaj

unread,
Sep 28, 2017, 7:07:39 AM9/28/17
to REST assured
I tried with all the solutions provided in this thread, still timeout is 60 secs(default time).

I tried following solutions.

1.  RestAssured.config = RestAssured.config().httpClient(HttpClientConfig.httpClientConfig()
                    .setParam( "CONNECTION_MANAGER_TIMEOUT", 2500000)
                    .setParam( "SO_TIMEOUT", 2500000));

2. RestAssuredConfig config = RestAssured.config().
                   httpClient(HttpClientConfig.httpClientConfig().setParam(ClientPNames.CONN_MANAGER_TIMEOUT, 2500000));

Most of different ways to set httpConnection parameters are deprecated.

Please help what httpConnection parameters can be use or is there any different way to increase timeout.

.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages