SpectoLabs / hoverfly-java

Java binding for Hoverfly
Apache License 2.0
168 stars 58 forks source link

@ClassRule fails with multiple tests executed via maven #184

Closed praisane closed 6 years ago

praisane commented 6 years ago

If using maven and the surefire plugin with default settings to execute more than one test using a the HoverflyRule as a @ClassRule in a superclass, only the first test succeeds as the next test will fail to connect to Hoverfly.

This happens because hoverfly-java's VM shutdown hook as already executed and shut it down. However the Hoverfly class instance remains loaded and thus its startedProcess field is non-null, which causes the next test to assume it's already initialized:

2018-07-19 08:34:53.794  WARN 68819 --- [           main] io.specto.hoverfly.junit.core.Hoverfly   : Local Hoverfly is already running.
2018-07-19 08:34:53.794  INFO 68819 --- [           main] io.specto.hoverfly.junit.core.Hoverfly   : Importing simulation data to Hoverfly
2018-07-19 08:34:53.797  WARN 68819 --- [           main] i.s.hoverfly.junit.api.HoverflyClient    : Failed to set simulation: Failed to connect to localhost/0:0:0:0:0:0:0:1:54356

To fix this issue I think the easiest way would be just to set the startedProcess field to null at the end of the io.specto.hoverfly.junit.core.Hoverfly. cleanUp() method.

Fortunately there's a workaround - disable forked VM reuse of the surefire plugin in your project's POM.

tommysitu commented 6 years ago

@praisane Just pushed a fix with your suggestion. Could you try it out please? You can use the snapshot version.

praisane commented 6 years ago

Hi @tommysitu

I can confirm that with version 0.11.1-SNAPSHOT the problem doesn't occur any more.

Thanks for the quick response, 'OPR

tommysitu commented 6 years ago

fixed in version 0.11.1