square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.74k stars 9.15k forks source link

Consecutive tests/calls fail, individiually they fail not #7874

Closed FeanorsCurse closed 1 year ago

FeanorsCurse commented 1 year ago

Hi,

Tests work individually but not when both are run. Exception in this case is:

Request processing failed; nested exception is feign.RetryableException: localhost:51483 failed to respond executing POST http://localhost:51483/feigntest; nested exception is org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.RetryableException: localhost:51483 failed to respond executing POST http://localhost:51483/feigntest org.springframework.web.reactive.function.client.WebClientRequestException: Request processing failed; nested exception is feign.RetryableException: localhost:51483 failed to respond executing POST http://localhost:51483/feigntest; nested exception is org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.RetryableException: localhost:51483 failed to respond executing POST http://localhost:51483/feigntest

Minimal (Spring Boot) project can be downloaded here.

BR, Daniel

yschimke commented 1 year ago

We can't really provide 1:1 support, please continue further discussion on a site like stackoverflow.

This is probably unsafe, so I'd start by using different MockWebServer instances per test.


    protected static MockWebServer mockWebServer;

    @BeforeAll
    public static void startMockServer() {
        try {
            mockWebServer = new MockWebServer();
            mockWebServer.start();
            System.out.println("### mockserver: " + mockWebServer.url("/").toString());
            System.setProperty("feign.baseUrl", mockWebServer.url("/").toString());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @AfterAll
    public static void stopMockServer() {
        try {
            mockWebServer.shutdown();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
FeanorsCurse commented 1 year ago

Thanks for the quick reply. As adviced, I tried with @BeforeEach as well, makes no difference.