Hello, some of our provider cannot verify its cont...
# pact-jvm
é
Hello, some of our provider cannot verify its contracts any more and return an emty list of pacts from http://broker.org/pacts/provider/ms.advice-conversation/for-verification
Copy code
{
  "_embedded": {
    "pacts": []
  },
  "_links": {
    "self": {
      "href": "<http://broker.org/pacts/provider/ms.advice-conversation/for-verification>",
      "title": "Pacts to be verified"
    }
  }
}
Yet I do have contracts in
/pacts/provider/ms.advice-conversation/
. What am I missing here?
I recently created environment on my broker, could that be the cause of it?
Copy code
docker run \
		--rm pactfoundation/pact-cli:latest \
		pact-broker \
		create-environment \
			--name prod \
			--display-name "Production environment" \
			--contact-name "see #pact-contract-testing-support" \
			--production \
			--broker-base-url $${PACT_BROKER_BASE_URL} \
			--verbose
m
The pacts to verify depends on selectors. What selectors are you using?
f
i also got that sometimes
é
@Matt (pactflow.io / pact-js / pact-go) I didn't configure any selectors, where can I see that?
f
when you set up wich pact to test , you don't use a consumer selector ?
for example in pactnet we have something like this
Copy code
ConsumerVersionSelectors =
                new[] {
                    new ConsumerVersionSelector {
                        MainBranch = true,
                        Consumer = ConsumerParticipant
                    }
                },
é
@Fábio Rodrigues Not at the moment
f
in jvm you should have something similar
é
We have this error in CI:
Copy code
> Task :testContract FAILED
AdvisorsControllerContractVerificationTest > pactVerificationTestTemplate(PactVerificationContext) > com.manomano.ms.advice_conversation.application.controllers.AdvisorsControllerContractVerificationTest.initializationError FAILED
    au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
    Provider: ms.advice-conversation
    Source: Pact Broker <https://broker.org>
        at app//au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:50)
f
you should have a log entry (maybe you need to set the log level to debug) where you can see the post call to retrieve the contracts
☝️ 1
something like POST <pactflowBaseUrl>/<provider>/for-verification with Json Body {xxxxxxx:xxx, xxxx:xxxxx}
in c# one:
Copy code
[10h26] 2022-08-31T07:31:01.8906579Z [DEBUG][pact_verifier::pact_broker] Sending JSON to <https://outsystems.pactflow.io/pacts/provider/application-versioning-service/for-verification> using POST: {"providerVersionTags":[],"includePendingStatus":true,"consumerVersionSelectors":[{"consumer":"publish-service","mainBranch":true}]}
see if you can find something similar
and what response it got
é
Got
POST
with
Copy code
"{"consumerVersionSelectors":[],"includePendingStatus":false}"
Copy code
08:59:10.342 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "POST /pacts/provider/ms.advice-conversation/for-verification HTTP/1.1[\r][\n]"
    08:59:10.345 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
    08:59:10.348 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Accept: application/hal+json, application/json[\r][\n]"
    08:59:10.349 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Accept-Encoding: gzip, x-gzip, deflate[\r][\n]"
    08:59:10.350 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Content-Length: 60[\r][\n]"
    08:59:10.351 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Host: <http://broker.org|broker.org> [\r][\n]"
    08:59:10.352 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "Connection: keep-alive[\r][\n]"
    08:59:10.355 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "User-Agent: Apache-HttpClient/5.1.3 (Java/11.0.16)[\r][\n]"
    08:59:10.356 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "[\r][\n]"
    08:59:10.361 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 >> "{"consumerVersionSelectors":[],"includePendingStatus":false}"
    08:59:10.388 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "HTTP/1.1 200 OK[\r][\n]"
    08:59:10.388 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "Date: Wed, 31 Aug 2022 08:59:10 GMT[\r][\n]"
    08:59:10.388 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "Content-Type: application/hal+json;charset=utf-8[\r][\n]"
    08:59:10.388 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "Content-Length: 191[\r][\n]"
    08:59:10.388 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "Connection: keep-alive[\r][\n]"
    08:59:10.389 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "Vary: Accept[\r][\n]"
    08:59:10.389 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "X-Pact-Broker-Version: 2.102.1[\r][\n]"
    08:59:10.389 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "X-Content-Type-Options: nosniff[\r][\n]"
    08:59:10.389 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "[\r][\n]"
    08:59:10.389 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-1 << "{"_embedded":{"pacts":[]},"_links":{"self":{"href":"<http://broker.org> /pacts/provider/ms.advice-conversation/for-verification","title":"Pacts to be verified"}}}"
We are using ``X-Pact-Broker-Version: 2.102.1` and pact lib
4.3.14
f
yeah, you're not using any selectors
try to set includePendingStatus as true
é
With the following consumer selectors I'm able to fetch the contract. However, it's still unclear to me why I need to specify the selector on this provider but not the other? Why do I need to specify the branch? I see many verified contract version include
HEAD
as a value
Copy code
@PactBrokerConsumerVersionSelectors
    public static SelectorBuilder consumerVersionSelectors() {
        return new SelectorBuilder()
            .branch("abmm-5295");  // why do I need to specify the branch?
    }
Is there a selectors to match the latest contract whatever branch/tag?
f
Maybe just send latest set to true and no branch,?
é
I'm able to fetch a contract when I specify the branch with which the contract is labelled (
abmm-5295
). However, I haven't specified any branch in most of our projets and we still are able to fetch and verify. Did a default behaviour regarding the contract fetching mechanism changes in the past few months? Or is it cheering luck that they passed? cc @Matt (pactflow.io / pact-js / pact-go)
Using
enablePendingPacts = "true"
doesn't prevent
initializationError
when I only selection from
mainBranch()
(which has no associated contracts)
Copy code
AdvisorsControllerContractVerificationTest > pactVerificationTestTemplate(PactVerificationContext) > com.manomano.ms.advice_conversation.application.controllers.AdvisorsControllerContractVerificationTest.initializationError FAILED
    au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException at PactJUnit5VerificationProvider.kt:50
b
@Édouard Lopez we could spend a lot of time trying to work out why it used to work and doesn’t now, but I think it would be better to spend that time adding in the branches and using them as recommended.
The Pact Broker is not expected to work without branches (or at least, tags, but they’re superseded by branches now)
1
This is the code that is used if there are no consumer version selectors provided. https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/pacts/pacts_for_verification_repository.rb#L138
but - you should be using consumer version selectors.
The default recommendation is: • publish pacts/verifications with a branch • verify the pacts from the main branch, and released/deployed.
That is
mainBranch()
and
deployedOrReleased()
é
Thanks, we are publishing from the merge request pipeline so the contract are not tagged with the
mainBranch
, that's a mistake
b
If it’s from the merge request pipeline, then they should be included in the WIP pacts.
é
Yep, WIP show them ✌️
👍 1