Connection reset in test using REST-assured

10,575

Are you making many requests in a short amount of time? You could try closing idle connections after each request and/or reuse the HTTP Client instance for multiple requests.

Share:
10,575
Barbra
Author by

Barbra

Updated on June 15, 2022

Comments

  • Barbra
    Barbra almost 2 years

    I have a test with the use of REST-assured. In this test when I pass full host and path to get() method, everything goes fine, test passes. But when I try to use RestAssured.baseURI and RestAssured.basePath like it's shown in this part of the tutorial: http://code.google.com/p/rest-assured/wiki/Usage#Default_values, test ends up with Connection reset. Below I paste working version and version with baseURI which doesn't work, and the error I get. Help please :>

    Working version:

    import com.jayway.restassured.RestAssured;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    import java.util.Iterator;
    
    import static com.jayway.restassured.RestAssured.basic;
    import static com.jayway.restassured.RestAssured.given;
    import static org.hamcrest.Matchers.containsString;
    
    public class SomeTest {
    
        @Test(dataProvider = "provideData")
        public void doSomeTest(String someParameter, String someExpectedValue) {
    
            given().
                    auth().basic("login", "pass").
                    param("someParameter", someParameter).
            when().
                    get("http://some.host/some-base-path/some-path-relevant-in-test").
            then().
                    statusCode(200).
                    body("some json", containsString(someExpectedValue)).
                    log().ifError();
        }
    
        @DataProvider(name = "provideData")
        public Iterator<Object[]> provideData() {
    
            //this provides data for test method in irrelevant way
        }
    
    }
    

    Not working version which results in Connection reset:

    import com.jayway.restassured.RestAssured;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    import java.util.Iterator;
    
    import static com.jayway.restassured.RestAssured.basic;
    import static com.jayway.restassured.RestAssured.given;
    import static org.hamcrest.Matchers.containsString;
    
    public class SomeTest {
    
        @Test(dataProvider = "provideData")
            public void doSomeTest(String someParameter, String someExpectedValue) {
    
            RestAssured.baseURI = "http://some.host";
            RestAssured.basePath = "/some-base-path";
    
            given().
                    auth().basic("login", "pass").
                    param("someParameter", someParameter).
            when().
                    get("/some-path-relevant-in-test").
            then().
                    statusCode(200).
                    body("some json", containsString(someExpectedValue)).
                    log().ifError();
        }
    
        @DataProvider(name = "provideData")
        public Iterator<Object[]> provideData() {
    
            //this provides data for test method in irrelevant way
        }
    }
    

    Error:

    mar 19, 2014 10:26:01 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
    INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
    mar 19, 2014 10:26:01 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
    INFO: Retrying request
    

    What am I doing wrong? :(

    • Dreamer
      Dreamer about 7 years
      hi Barbra How did you fix the issue? I have the same situation here, connection rest on specific restful calls while serializing entities.
  • Barbra
    Barbra about 10 years
    Actually as it is a poc this is whole my code at the moment except from that data providing part so I don't make many request. But I added the config that you mentioned. Unfortunatelly it didn't change anything but thank you anyway :) Maybe I set baseURI and/or basePath in a wrong manner but following the documentation I can't figure out how else I should do this to make it work...