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

Pending test causes build failure when using MessageTestTarget #1573

Closed
chason-choate opened this issue Jun 14, 2022 · 1 comment
Closed
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@chason-choate
Copy link

We have a provider build that pulls contracts from pactflow. We've enabled all pending test options and see the appropriate lines in the logs. We have one case in the contract that is expected to fail but since it's pending it should not fail the build. Unfortunately it does fail the build and can be replicated locally/consistently.

Below you'll find our standard provider test case and some relevant logs:

@PactBroker
@Provider("ExtractorProvider")
class ExtractorProviderTest {

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider::class)
    fun pactVerificationTestTemplate(context: PactVerificationContext) {
        context.verifyInteraction()
    }

    @BeforeEach
    fun beforeEach(context: PactVerificationContext) {
        context.target = MessageTestTarget(packagesToScan = listOf(this::class.java.packageName))
    }

    @State("Outputting data")
    fun prepOutputData() {
        println("TEST ------------")
    }

    @PactVerifyProvider("Message one")
    fun `generate message one output`(): String {
        return "{}"
    }

    @PactVerifyProvider("Message two")
    fun `generate message two output`(): String {
        return "{}"
    }
}

Logs: (Note these logs are here just to illustrate that the pending flag has been enabled but the overall maven build will still fail)

15:57:50.221 [main] INFO  a.c.d.p.p.j.PactVerificationStateChangeExtension - Invoking state change method 'Outputting data':SETUP
TEST ------------

Verifying a pact between ClientConsumer (0.9.1-SNAPSHOT-5f778a9) and ExtractorProvider [PENDING]

  Notices:
    1) The pact at ... is being verified because the pact content belongs to the consumer version matching the following criterion:
    * latest version of ClientConsumer from the main branch 'master' (0.9.1-SNAPSHOT-5f778a9)
    2) This pact is in pending state for this version of ExtractorProvider because a successful verification result for a version of ExtractorProvider with tag 'testing' has not yet been published. If this verification fails, it will not cause the overall build to fail. Read more at https://docs.pact.io/go/pending

  [from Pact Broker ...]
  Given Outputting data
  Message two

  Test Name: ...(AsynchronousMessage)
            
    generates a message which
      has a matching body (FAILED)
      has matching metadata (OK)

Failures:

1) Message one: generates a message which has a matching body

    1.1) body: $ Actual map is missing the following keys: ...

        {...}

After a bit of research into the codebase I noticed this line which will be set to ANNOTATED_METHOD when using the MessageTestTarget.

Then the code flows ultimately to here which always sets the pending flag to false. Updating that to consumer.pending seems to resolve our issue when testing locally.

Hope that provides some insight into the issue. Let me know if I can provide any more info.

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jul 26, 2022
@snukone
Copy link

snukone commented Oct 25, 2022

Successfully tested the bugfix with Pact-JVM Versions 4.3.12, 4.3.13, 4.3.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants