-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
Json parsing error thrown while running the service consumer test #475
Comments
The JSON parser is failing to parse the pact file. Looks like it might be either a corrupt file or the file has the wrong content type. In what environment are the tests running? (Linux/Windows etc.) |
Cool, I will verify the content-type, is there a way to validate corrupt pact file? |
Open it in a text editor. |
cool, on it. thanks @uglyog |
Hey @uglyog , I looked at content-type values and also verified the pact json file but cant zero in on anything potentially causing this error. Any other element which might be causing it? Btw this surfaces only while running the test with
|
Also , the tests are running on mac (local) and Linux (CI). |
Assuming that a previous test was generating a Pact file that the current test could not read I started commenting things out and eventually discovered that when we replace the matchPath method call: return builder
.given("User can fetch subscription setting")
.uponReceiving("GET subscription setting")
.matchPath("(/!?rest)?/cards/1.0/events/subscription", "rest/cards/1.0/events/subscription")
.method("GET")
.willRespondWith()
.status(HttpStatus.SC_OK).headers(ImmutableMap.of("Content-Type", "application/json"))
.body(GSON.toJson(response))
.toPact(); with the path method call: return builder
.given("User can fetch subscription setting")
.uponReceiving("GET subscription setting")
.path("rest/cards/1.0/events/subscription")
.method("GET")
.willRespondWith()
.status(HttpStatus.SC_OK).headers(ImmutableMap.of("Content-Type", "application/json"))
.body(GSON.toJson(response))
.toPact(); it fixes the problem. This pact mock configuration is part of a test that runs and passes prior to the test that fails. I've just tried to reproduce the problem in a simpler example and was unable to get it to fail so I'm not too sure what exactly is tripping up the parser. I hope this helps you guys narrow in on the root cause problem. |
Hey @uglyog , I tried using pact DSL directly for the consumer tests in hope that it will perhaps fix how pact file is read/written and also applied Ben's approach for |
From the stack trace, it looks like the failure happens when the test is successful, and pact-jvm is trying to merge the generated pact file with the one that already exists on disk. It is the one on disk that is causing the issue. Could you run a clean before the tests? |
yeah I did run Another observation, I have 3 classes and 4 unit tests and occasionally one test is not executed and the On a hunch that since |
Ok, we're getting closer. The different between running things in IntelliJ and Gradle is that Gradle could run tests concurrently in different threads. I'm assuming you're using the Android Gradle plugin? Are you're tests running as unit tests or instrumented tests (under androidTest)? |
Thats correct, they are unit tests ( not the instrumented tests) . And yes we are using Android gradle plugin to run the tests. |
Also, after making all the above changes, I think it has come to a point where all the tests are running successfully but the pact file doesn't capture all the interactions (2/4). Guess its just that I am not running into concurrency scenario now. Any hints? |
Can you check that the four interactions have a unique description. They may be overwriting the older ones (the provider state and description should be unique). I'm going to add a file system lock to the pact writing code to protect against this type of issue. |
Thats right they are not always unique. This issue is surfacing because we were forking 4 test worker process for running our unit test using Junit runner. Gradle In module gradle,
In root gradle,
Looks a bit clunky though 😞 |
I definitely need to put that synchronisation check in before writing the pact file. |
… with an existing one on the file system #475
Version 3.5.2 has been released with synchronisation and file locking on the pact file. |
… with an existing one on the file system #475 Conflicts: pact-jvm-model/src/main/groovy/au/com/dius/pact/model/BasePact.groovy pact-jvm-model/src/main/kotlin/au/com/dius/pact/model/Pact.kt
Conflicts: pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/Defect464Test.java
Hey guys,
We have a pact-jvm(pact-jvm-consumer-junit_2.11:3.4.1) setup running the junit tests to generate the pact file.Recently we have started getting this error while running the tests. Stacktrace doesnt give a lot of info but looks like some discrepancy in reading the Pact file. Not sure if its how I am generating the response causing the issue.
This is one of the interaction setup where we are getting this error,
And this is how the json from pact file looks like,
The text was updated successfully, but these errors were encountered: