-
-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subsequent tests fails in au.com.dius.pact:consumer for a project using ApacheHttpClient #1383
Comments
Thanks for the example project. Please note that this is not a Pact-JVM issue, but an issue with HTTP clients caching connections with HTTP/1.1 and not taking the port into account (i.e. the connections are cached based on host name). The reason the sleep works because it causes the time to live value for the connection in connection pool to be exceeded and it will be evicted when the second test runs. One way to fix it is to change: public class MyFeignConfiguration {
@Bean
public feign.Client client() {
CloseableHttpClient httpClient = HttpClientBuilder.create()
.setConnectionReuseStrategy(new NoConnectionReuseStrategy())
.build();
return new ApacheHttpClient(httpClient);
}
} Another way is to enable using system properties on the HTTP client and then set the public class MyFeignConfiguration {
@Bean
public feign.Client client() {
CloseableHttpClient httpClient = HttpClientBuilder.create()
.useSystemProperties()
.build();
return new ApacheHttpClient(httpClient);
}
} and then in the project POM add: <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<systemProperties>
<property>
<name>http.keepAlive</name>
<value>false</value>
</property>
</systemProperties>
</configuration>
</plugin> |
Duplicate of #342 |
Added a note to readme about persistent HTTP/1.1 connections: https://github.com/pact-foundation/pact-jvm/tree/master/consumer#dealing-with-persistent-http11-connections-keep-alive |
I created a sample with a failing test: https://github.com/mjureczko/pact-consumer-issue.
When running tests on the consumer side in a series where each test case requires the same provider endpoint, but in a different state, the second test fails without a response from the provider. It fails unless I give it some additional time (sleep for 1-2 seconds). I was tinkering with the debugger and the sleep is apparently required after executing
server.stop(0)
in theMockHttpServer.kt
. So according to my observations, the mock server is restarted between test cases, and during the teardown, something is done asynchronously, unfortunately, not fast enough.The text was updated successfully, but these errors were encountered: