https://linen.dev logo
#help
Title
# help
g

Gal Gilboa

10/12/2023, 9:52 AM
Hello, I have upgraded my jar from ‘com.github.tomakehurstwiremock-jre8-standalone:2.33.2’ to ‘org.wiremockwiremock standalone3.2.0’ The way i used wiremock i am using wiremock server as mock server for running unit test (using @TestTemplate) i am starting the mock server before each sub test and stopping it right after it finishes. my problem is: What i am getting is occasional test failure (non deterministic behaviour) that is a result of a test trying to start the server on a port that is already in use…..(guess other test is not finished yet). the error i am getting:
Copy code
com.github.tomakehurst.wiremock.common.FatalStartupException: java.lang.RuntimeException: java.io.IOException: Failed to bind to /0.0.0.0:9888
Caused by: java.lang.RuntimeException: java.io.IOException: Failed to bind to /0.0.0.0:9888
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:9888
Caused by: java.net.BindException: Address already in use
it seems, that since the upgrade, the tests are acting as if they are running in parallel. Any explanation/solution for this? Thanks, Gal.
t

Tom

10/12/2023, 10:06 AM
Hi @Gal Gilboa how are you starting and stopping the WireMock server?
g

Gal Gilboa

10/12/2023, 10:23 AM
i am using the simple start/stop method on my server
Copy code
public void startAll() {
   this.getMockServers().stream().forEach(mockServer -> mockServer.start());
  <http://logger.info|logger.info>("Started mock servers");
}
this method is eventually(not directly) being called from a ‘beforeEach’ method of a class implementing the BeforeEachCallback, AfterEachCallback extentions
Copy code
@Override
public void beforeEach(ExtensionContext context) throws Exception {
 myservers.startAll()
}
the servers are define as follows:
Copy code
WireMockServer wireMockServer = new WireMockServer(
        WireMockConfiguration.wireMockConfig()
          .port(proxy.getPort())
          .extensions(PriorityPostServeAction.class) 
          .notifier(new ConsoleNotifier(true)));
      mockServers.add(wireMockServer);
t

Tom

10/12/2023, 10:24 AM
Are you explicitly stopping them afterwards or just allowing them to be GC’d?
g

Gal Gilboa

10/12/2023, 10:27 AM
i am stopping them explicitly- the same way i have started them.
in the afterEach method
4 Views