Skip to content
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

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

Closed
paulspencerwilliams opened this issue Jul 10, 2018 · 5 comments

Comments

@paulspencerwilliams
Copy link

paulspencerwilliams commented Jul 10, 2018

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.

@minhdoan159
Copy link

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@

@paulspencerwilliams
Copy link
Author

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); }

@uglyog
Copy link
Member

uglyog commented Jul 14, 2018

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.

@DrongoX
Copy link

DrongoX commented Apr 24, 2019

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

@uglyog
Copy link
Member

uglyog commented May 3, 2019

It won't be dependent on the HTTP method, but on how the HTTP client library caches the connection.

@uglyog uglyog closed this as completed Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants