Is it expected that a NoPactsFoundException would ...
# pact-jvm
d
Is it expected that a NoPactsFoundException would be thrown when the only Pacts available in the Pact-broker are already verified? I am seeing strange, seemingly sporadic behavior when running Pact tests from my provider side. Sometimes it works, but most of the time when I run the provider tests I get the following error:
Copy code
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: 
No Pact files were found to verify
Provider: MY-PROVIDER
Consumer: MY-CONSUMER
I've spent a few days on this, and now I am wondering if the issue isn't actually a failure to find Pacts, but a failure of finding Pacts that need to be verified by the provider. After I publish Pacts to the broker from my consumer, I trigger a pipeline in the consumer repo, which seems to always pass 100% of the time. But, when my provider repo initiates the job to verify the Pacts, I will see this exception. If this is expected, I think that adding the
IgnoreNoPactsToVerify
annotation would fix this. Wondering if this is by design, or if I have a bug somewhere. Thanks for the help!
m
If it can't find pacts to verify it could be one of a few things. If it's intermittent that sounds like the selectors you are using aren't finding anything. It would help to understand your setup - what selectors you're using and how your consumers are publishing and adding branch info etc
Also have you read the CI/CD setup guide? (howtolearn)
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
d
Thanks for the reply, Matt. Here is a little more context on our setup: From reading the documentation, I believe we have achieved step 5 in Pact nirvana 🙂 Repo A is the consumer. We write and publish Pacts to our Pactbroker (not self hosted) on merge requests. After we publish, we trigger a multi-project pipeline in Gitlab to Repo B, which is a provider. Repo B, in the same commit for the pipeline, will bring up their service and run the Pact tests. We pass them a variable which tells them which branch we are working on, so they can fill this into a ConsumerVersionSelector. From our testing, we see that this pipeline will always find Pacts to verify (no NoPactsFoundException), and verify them successfully. When we merge to our main branch, this runs, and updates the latest branch selector for
mainline
. We are hitting the issue I described above when Repo B runs their Pacts as a part of their normal pipeline flow. When they are running their Pact verify job (which stands up the service and runs the pacts), they always point at our
mainline
branch.
🙌 1
m
Thanks, can you please confirm the selectors you’re using in the “normal” pipeline? That’s probably the issue.
d
In Repo A (consumer), we always trigger the multi-project pipeline against Repo B's
develop
branch (this is the main branch for their repo) and pass in a variable which gets passed into their selector code:
Copy code
@PactBrokerConsumerVersionSelectors
    fun consumerVersionSelectors(): SelectorBuilder {
        val selectorBuilder: SelectorBuilder = SelectorBuilder()
        return selectorBuilder.branch(System.getProperty("consumer.branch", "mainline"), "SOS")
    }
In Repo B (provider), as a part of their MR pipeline, they always point to Repo A's
mainline
branch (this is the main branch for our repo). This is what makes me wonder if I have my mental image of the flow wrong. Whenever Repo A has an MR, we publish the new pacts and immediately ask Repo B to verify.
The code sample posted above is in our Provider repo
m
Thanks. Hard to say without seeing the branch/tag information associated with the consumer pacts. I’m assuming you’ve read https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors? You could probably just use
mainBranch
(that way the provider need not hard code the consumer’s branch). You probably also want
deployedOrReleased
(see recommended). If that’s not catching the right stuff, then: 1. there is no branch information on the consumers and they aren’t deployed to any environment 2. there is a bug somewhere To identify (2), we’d need at least some view of the matrix - are you using the OSS Pact Broker or PactFlow?
r
I'm a co-worker of Devin's. This has continued to be an intermittent (though frequent) issue for us. We are using PactFlow. Here is the most recent element in our matrix, which shows SOS having a mainline branch and tag. We aren't using environments.
👍 1
Using this
return selectorBuilder.branch(System.getProperty("consumer.branch", "mainline"), "SOS")
Gives me this output:
Copy code
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
Provider: DASHBOARD
Consumer: SOS
Source: Pact Broker <https://smartsheet2.pactflow.io> consumerVersionSelectors=[Branch(name=mainline, consumer=SOS, fallback=null)]
If I don't specify any consumer version selector, the tests run as expected, against the most recently published consumer pact.
If I specify the mainline tag, it finds a bunch of tests to run.
Using
selector.mainBranch()
returns a similar error as above:
Copy code
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
Provider: DASHBOARD
Consumer: SOS
Source: Pact Broker <https://smartsheet2.pactflow.io> consumerVersionSelectors=[au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors$MainBranch@6cdfd50a]
m
Sorry I missed this guys, looking into it now…
Any chance you could please share
DEBUG
level logs with me from the verification process? That would really help
Actually, could you please send them to SmartBear support? I’ll be on leave from today, and don’t want this to get lost (howtosmartbearsupport)
s
Please create a ticket here with the issue details so that we can properly track the resolution and the PactFlow product support team will continue to work through it with you: https://support.smartbear.com/pactflow/message