It would appear that having consumer code that issue PUT requests on Pact's mock server cause issues if tests co-exist in the same JUnit test class.
I've created a simple exemplar project to replicate this issue. To replicate, follow these instructions:
git clone [email protected]:paulspencerwilliams/BugExampleWithPactAndPutRequests.git
./gradlew test -i
git checkout works-with-posts
./gradlew test -i
The second test on the works-with-posts branch would appear to prove this is PUT related.
Hi @paulspencerwilliams ,
I faced an issue with PUT request mixed with others as your case. And i find out that i must use a wrapper for RestTemplate (configure a timeout value) before calling it. IThe mock server maybe need a wait-time/timeout to proceed the PUT request, refer to #8 Configure Timeout of this link for more detailed info:
http://www.baeldung.com/rest-template
Hope it help@
Hey @minhdoan159, a colleague also discovered the timeout hack, and we've temporarily worked around this issue using @BeforeEach
public void pause() throws InterruptedException {
Thread.sleep(5000L);
}
Thanks for the example project!
My guess is that this is related to the RestTemplate using a connection cache (see #342 for a similar issue). As each test gets a new mock server, any cached connection on the second test will be stale. A five second sleep might be enough time for the RestTemplate HTTP connection library to get a new connection.
Changing the test to use a different port for each test passes.
Hi guys, just had the same issue with HTTP PATCH, so not only PUT
It won't be dependent on the HTTP method, but on how the HTTP client library caches the connection.
Most helpful comment
Hi guys, just had the same issue with HTTP PATCH, so not only PUT