Pact-jvm: Tests concerning PUTs can't coexist with other JUnit 5 tests with pact-jvm-consumer-junit5_2.12

Created on 10 Jul 2018  路  5Comments  路  Source: pact-foundation/pact-jvm

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.

Most helpful comment

Hi guys, just had the same issue with HTTP PATCH, so not only PUT

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BramVanImpe picture BramVanImpe  路  6Comments

audunhalland picture audunhalland  路  4Comments

ajhcpt picture ajhcpt  路  9Comments

leisyj picture leisyj  路  5Comments

uglyog picture uglyog  路  4Comments