Hi, following a previous post, I’m still seeking h...
# help
t
Hi, following a previous post, I’m still seeking help. I’m using wiremock-standalone v3.7.0 in my tests with JUnit5. Each individual test passes when run separately, but when running together, only the first test case works while the others simply hang. Is there something I can look into to fix this? Thanks! The initialization looks as follows:
Copy code
@WebMvcTest(controllers = HerokuResource.class)
@AutoConfigureMockMvc
@WireMockTest(httpPort = 8200)
@ActiveProfiles("test")
@Slf4j
@TestPropertySource(properties = {
        "sm.url=<http://localhost:8200>",
        "sm.hostname=localhost",
        "sm.basic.auth.username=user",
        "sm.basic.auth.password=12345",
        "statemachine.retries=2",
        "statemachine.waitms=3600"
})
class WireMockTest extends ITBase {
All tests uses same stubs. I have a function which I call from a @BeforeEach
r
what does your @BeforeEach function look like?
t
Copy code
@BeforeEach
    public void setUp() throws InterruptedException {
        jedis = jedisPool.getResource();
        redisCleanup(jedis, uuid);
        setupStubs();
    }

private void setupStubs() {
        // Subscription
        stubFor(WireMock.get(WireMock.urlPathEqualTo("/subscription"))
                .willReturn(aResponse()
                        .withStatus(204)
                        .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
                        .withHeader("Accept", MediaType.APPLICATION_JSON_VALUE)
                        .withHeader("Authorization", authorization_redis)
                        .withBody(""))); // No subscriptions

        stubFor(<http://WireMock.post|WireMock.post>(WireMock.urlPathMatching("/subscription.*"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
                        .withHeader("Accept", MediaType.APPLICATION_JSON_VALUE)
                        .withBody("{\"subscription_id\": \"4444\", \"account_id\": \"2222\", \"status\": \"active\"}")));

// many more others 
}
r
youll likely need to reset your wiremock instance before setting up stubs.
WireMock.reset()
should do the job
t
I added it but still no effect 😕
r
subsequent tests are just hanging? are they timing out eventually? can you see any error logs?
t
All subsequent tests are hanging; only the first one passes. There are no error logs. When I’m in debug mode on the HTTP call function, I see that the request is sent, but it doesn’t reach the
validateNoErrorResponse
Copy code
private CloseableHttpResponse makeHttpPost(String url, String body) throws IOException {
    HttpPost postRequest = initHttpPost(url);
    postRequest.setEntity(new StringEntity(body));
    CloseableHttpResponse response = httpClient.execute(postRequest);

    validateNoErrorResponse(response);
    return response;
}
r
it's pretty difficult to diagnose the problem based off the code snippets here. if you can create a minimal project that demonstrates the issue, i can take a look