简体   繁体   中英

Connection reset in test using REST-assured

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? :(

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.

It seems to be a bug in Restassured fixed on version 2.8.1. There was a leakage of resources, connections weren't closed. See https://github.com/rest-assured/rest-assured/issues/633 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM