0

I have some end-to-end UI tests with WebDriver that use a remote wiremock instance, that I connect to in the following way:

@Configuration
public class WireMockConfiguration {
    @Bean
    public WireMock wireMock() {
        return new WireMock("my-pyroxy.corp", 8080);
    }
}

I have noticed that after tests finish, the wiremock server receives a shutdown request. The Wiremock::shutdown method is not marked with any annotation like @PreDestroy but Spring is still invoking it.

How do I stop it (apart from creating this wiremock client bean outside of the spring context?)

Ubeogesh
  • 1,633
  • 2
  • 15
  • 22
  • `shutdown` like `close` is a method automatically detected as a shutdown method. If you don't want it to be invoked configure the `@Bean` with an empty method. However after the tests finishes this method will only be invoked if the application context is shutdown (which appears to be the case). When using Spring testing properly it should be cached (and thus reused). So please do share the tests you are running. – M. Deinum Jan 30 '23 at 13:03
  • The wiremock server instance is static and independent of the tests. It is shared between different test instances. My question is, what is the best way to prevent spring from automatically shutting down the wiremock server. – Ubeogesh Jan 30 '23 at 13:17
  • It isn't static as it is in a configuration and thus part of the lifecycle of Spring. If it is static, don't make it a bean but create a static instance in some top-level test method. – M. Deinum Jan 30 '23 at 13:19
  • You're confusing wiremock client and server. Wiremock Server is instantiated as new `WireMockServer()` whereas `new WireMock()` is a client. In my case, the server is running on a whole different host (as can be inferred from how I instantiate the client - sorry if that wasn't clear) – Ubeogesh Jan 30 '23 at 13:23

1 Answers1

1

From the documentation of @Bean, I have learned this

To disable destroy method inference for a particular @Bean, specify an empty string as the value, e.g. @Bean(destroyMethod="")

Ubeogesh
  • 1,633
  • 2
  • 15
  • 22