wiremock: Https test hang forever
Wiremock version: 2.1.11 I have a simple test like this
@Rule
public final WireMockRule service = new WireMockRule(wireMockConfig().httpsPort(8443));
@Before
public void setup() {
service.stubFor(post(urlEqualTo("/some/endpoint"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")));
}
@Test
public void test() {
// sending request to https://myserver.com:8443/some/endpoint
Response response = client.request();
Assert.assertEquals(200, response.getStatus());
}
However, the test hangs forever at the requesting step.
The test will eventually timeout with this stacktrace
testSendMessage(com.opower.dyn.TestSendApi) Time elapsed: 75.409 sec <<< ERROR!
javax.ws.rs.ProcessingException: java.net.ConnectException: Operation timed out
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:184)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:227)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:422)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:412)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:321)
at com.opower.dyn.SendApi.sendMessage(SendApi.java:55)
at com.opower.dyn.TestSendApi.testSendMessage(TestSendApi.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:72)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (3 by maintainers)
Commits related to this issue
- Fix flaky tests Force the connections in wiremock tests to be closed. See https://github.com/tomakehurst/wiremock/issues/485 — committed to codecentric/spring-boot-admin by joshiste 6 years ago
- DIV-3775 - attempt to fix flaky test by setting connection close https://github.com/tomakehurst/wiremock/issues/485#issuecomment-382221826 — committed to hmcts/div-case-maintenance-service by hosainnet 5 years ago
- DIV-4672 amend family man keep (#123) * Keep the D8 Case Ref property when creating the Amend draft (Family Man Ref) * Apply testing config for AKS * DIV-4679 - initial work to run integration ... — committed to hmcts/div-case-maintenance-service by alexwakeman 5 years ago
- Fix flaky tests Force the connections in wiremock tests to be closed. See https://github.com/tomakehurst/wiremock/issues/485 — committed to adamsbusiness/spring-admin by joshiste 6 years ago
- Fix flaky tests Force the connections in wiremock tests to be closed. See https://github.com/tomakehurst/wiremock/issues/485 — committed to ejavexpert/java-spring-boot-admin by ejavexpert 6 years ago
- Fix flaky tests Force the connections in wiremock tests to be closed. See https://github.com/tomakehurst/wiremock/issues/485 — committed to KingSize0319/spring-boot-admin by KingSize0319 6 years ago
I also came across this kind of problem where Wiremock starts to hang when multiple tests are ran in a suite. I realized at some point that the stub definition of my responses didn’t include the
Connection: Close
http header. I tried adding it and it seems to have fixed the issue.Since I’m lazy and don’t want to forget adding it somewhere, I wrote a simple extension that I add to my WireMockRule:
I hope this helps!