pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

"Unexpected end event" running provider tests in gradle #1310

Open PhilHardwick opened 3 years ago

PhilHardwick commented 3 years ago

I'm getting this error ("Unexpected end event") with pending pacts on pact-jvm version 4.1.17. #1221 mentioned the same thing but these pacts are for a service in production, so I don't think we had put things in a bad state - although I won't rule out the possibility. But I wanted to check if the following is correct:

From what I'm seeing, Gradle has a cache of tests it's executing as you said (in the other issue). It puts the current test in the cache when the Junit notifier calls the test started method. Pact does this manually here: https://github.com/pact-foundation/pact-jvm/blob/c91f44d2a523240b69899d2c705937ae9cbb5448/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/InteractionRunner.kt#L158

As you can see this doesn't happen if it's a pending pact. However further down the InteractionRunner calls the fireTestFinished method for pending pacts: https://github.com/pact-foundation/pact-jvm/blob/c91f44d2a523240b69899d2c705937ae9cbb5448/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/InteractionRunner.kt#L170 (the if statement for pending pacts happens a few lines later) - this causes the issue of "Unexpected end event". Should the call to fireTestFinished be wrapped in an if (!pending)?

What I'm not sure about is why this is happening for just this test - and not in any of the other services that run pact tests. I'll try debug through the same points and see what happens in other services tomorrow.

uglyog commented 3 years ago

For pending pacts, it should fire TestIgnored not TestStarted and then not fire TestFinished. It might be because the pending test is actually passing, so it is then firing the TestFinished event. I think it does need the if guard.

uglyog commented 3 years ago

4.1.18 released