Hi all! I hope you're all doing well. I'm relative...
# pact-broker
s
Hi all! I hope you're all doing well. I'm relatively new to Pact testing and have encountered an issue that's been puzzling me. I did a thorough search through this channel and the Pact Broker issues, but I couldn't find a solution, so I thought I'd reach out to this knowledgeable community for some guidance. Here's the situation: We have our Pact Broker up and running on our localhost, and it's accessible through a public IP address. On the frontend side (Angular app), I've successfully executed Pact tests and generated the Pact contract, which I've also managed to publish on the Pact Broker. However, when I attempt to verify the Pact test from my Node.js backend, I run into an issue that reports: "Failed to load pact - Could not load pacts from pact broker 'http://18.237.96.220:9292/'." I've included the logs below for your reference:
Copy code
[22:51:11.120] INFO (39344): pact@12.1.0: Verifying provider
[22:51:11.373] INFO (39344): pact-core@14.0.4: Verifying Pacts.
[22:51:11.377] WARN (39344): pact-core@14.0.4: Using the tag 'latest' is not recommended and probably does not do what you intended.
[22:51:11.378] WARN (39344): pact-core@14.0.4:     See <https://docs.pact.io/pact_broker/tags/#latest-pacts>
[22:51:11.379] WARN (39344): pact-core@14.0.4:     If you need to specify latest, try:
[22:51:11.379] WARN (39344): pact-core@14.0.4:        consumerVersionSelectors: [{ lastest: true }]
[22:51:11.380] INFO (39344): pact-core@14.0.4: Verifying Pact Files
[22:51:11.382] DEBUG (39344): pact-core@14.0.4: Initalising native core at log level 'DEBUG'
[22:51:11.383] DEBUG (39344): pact-core@14.0.4: binding path #0: : attempting to load native module from:
 - C:\Users\saya2660\cxt\rental-customer-service\node_modules\@pact-foundation\pact-core\prebuilds\win32-x64
   source: pact-js-core binding lookup

 - You can override via PACT_PREBUILD_LOCATION

[22:51:11.505] INFO (39344): 0.4.7: pact native library successfully found, and the correct version
2023-09-12T17:21:11.524666Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked
2023-09-12T17:21:11.537949Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked
[22:51:11.541] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment
2023-09-12T17:21:11.546913Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_state FFI function invoked
2023-09-12T17:21:11.554269Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked
[22:51:11.551] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetPublishOptions' was not executed as it had non-fatal validation errors: No publishVerificationResult option / PACT_BROKER_PUBLISH_VERIFICATION_RESULTS set, or no providerVersion option
[22:51:11.552] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: Either no consumerFilters option provided, or the array was empty
[22:51:11.553] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetFailIfNoPactsFound' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided
[22:51:11.556] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided
[22:51:11.557] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided
2023-09-12T17:21:11.563454Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked
[22:51:11.567] DEBUG (39344): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided
2023-09-12T17:21:11.664723Z DEBUG ThreadId(02) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_execute FFI function invoked
2023-09-12T17:21:11.665825Z DEBUG ThreadId(02) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(<http://18.237.96.220:9292/>, provider_name='customer-service', enable_pending=false, include_wip_since=None, provider_tags=["latest"], provider_branch=Some(""), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: Some("latest"), fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }], auth=Token(PACT*************)')
2023-09-12T17:21:11.701775Z DEBUG ThreadId(02) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/content-generator/binary
core/content-generator/json
core/content-matcher/json
core/content-matcher/multipart-form-data
core/content-matcher/text
core/content-matcher/xml
2023-09-12T17:21:11.701953Z DEBUG ThreadId(02) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/matcher/v1-equality
core/matcher/v2-max-type
core/matcher/v2-min-type
core/matcher/v2-minmax-type
core/matcher/v2-regex
core/matcher/v2-type
core/matcher/v3-content-type
core/matcher/v3-date
core/matcher/v3-datetime
core/matcher/v3-decimal-type
core/matcher/v3-includes
core/matcher/v3-integer-type
core/matcher/v3-null
core/matcher/v3-number-type
core/matcher/v3-time
core/matcher/v4-array-contains
core/matcher/v4-equals-ignore-order
core/matcher/v4-max-equals-ignore-order
core/matcher/v4-min-equals-ignore-order
core/matcher/v4-minmax-equals-ignore-order
core/matcher/v4-not-empty
core/matcher/v4-semver
2023-09-12T17:21:11.735709Z  INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/' from pact broker
2023-09-12T17:21:11.747320Z DEBUG ThreadId(02) hyper::client::connect::http: connecting to 18.237.96.220:9292
2023-09-12T17:21:12.034277Z DEBUG ThreadId(02) hyper::client::connect::http: connected to 18.237.96.220:9292
2023-09-12T17:21:12.362421Z DEBUG tokio-runtime-worker hyper::client::pool: pooling idle connection for ("http", 18.237.96.220:9292)
2023-09-12T17:21:12.364975Z DEBUG ThreadId(02) pact_verifier::pact_broker: Link URL is templated
2023-09-12T17:21:12.365079Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = <http://18.237.96.220:9292/pacts/provider/{provider}/for-verification>
2023-09-12T17:21:12.376050Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = <http://18.237.96.220:9292/pacts/provider/customer-service/for-verification>
2023-09-12T17:21:12.376229Z  INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/pacts/provider/customer-service/for-verification' from pact broker
2023-09-12T17:21:12.376309Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", 18.237.96.220:9292)
2023-09-12T17:21:12.376613Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 246 bytes
2023-09-12T17:21:12.680599Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-09-12T17:21:12.680652Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (2422 bytes)
2023-09-12T17:21:12.680689Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-09-12T17:21:12.680724Z DEBUG tokio-runtime-worker hyper::client::pool: pooling idle connection for ("http", 18.237.96.220:9292)
2023-09-12T17:21:12.681090Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = <http://18.237.96.220:9292/pacts/provider/customer-service/for-verification>
2023-09-12T17:21:12.683326Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = <http://18.237.96.220:9292/pacts/provider/customer-service/for-verification>
2023-09-12T17:21:12.683471Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to <http://18.237.96.220:9292/pacts/provider/customer-service/for-verification> using POST: {"providerVersionTags":["latest"],"includePendingStatus":false,"consumerVersionSelectors":[{"tag":"latest","latest":true}],"providerVersionBranch":""}
2023-09-12T17:21:12.683572Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", 18.237.96.220:9292)
2023-09-12T17:21:12.684186Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 458 bytes
2023-09-12T17:21:12.984970Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-09-12T17:21:12.985020Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (161 bytes)
2023-09-12T17:21:12.985054Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-09-12T17:21:12.985089Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", 18.237.96.220:9292)
2023-09-12T17:21:12.987343Z ERROR ThreadId(02) pact_verifier: Could not load pacts from pact broker '<http://18.237.96.220:9292/>': Link/Resource was not found - No pacts were found for this provider
2023-09-12T17:21:12.988589Z ERROR ThreadId(02) pact_verifier: Failed to load pact - Could not load pacts from pact broker '<http://18.237.96.220:9292/>'
2023-09-12T17:21:12.989454Z  WARN ThreadId(02) pact_matching::metrics:

Please note:
We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.

2023-09-12T17:21:12.990398Z DEBUG ThreadId(02) pact_matching::metrics: Sending event to GA - {"t": "event", "cd6": "pact_ffi", "ec": "ProviderTest", "cd7": "1.1.5", "cid": "015df3ce8fa36b46e3a85d45041b663b", "ea": "Completed", "ev": "0", "ds": "client", "tid": "UA-117778936-1", "v": "1", "av": "14.0.4", "cd3": "windows-x86_64", "cd2": "unknown", "an": "pact-core", "aip": "true", "el": "Pacts verified", "aid": "pact-core"}

Failures:

1) Failed to load pact - Could not load pacts from pact broker '<http://18.237.96.220:9292/>'

There were 1 pact failures

2023-09-12T17:21:13.247462Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=GoAway { error_code: NO_ERROR, last_stream_id: StreamId(0) }
2023-09-12T17:21:13.247543Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERROR, Library)
2023-09-12T17:21:13.247930Z DEBUG ThreadId(02) pact_plugin_driver::plugin_manager: Shutting down all plugins
[22:51:13.258] DEBUG (39344): pact-core@14.0.4: shutting down verifier with handle 0
2023-09-12T17:21:13.263227Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_shutdown FFI function invoked
[22:51:13.259] DEBUG (39344): pact-core@14.0.4: response from verifier: null, 1
[22:51:13.260] ERROR (39344): pact-core@14.0.4: Verification unsuccessful
 FAIL  tests/pact-testing/provider.spec.ts (7.312 s)
  Pact Provider verification
    × Should verify customer rental services contracts (2167 ms)

  ● Pact Provider verification › Should verify customer rental services contracts

    Verfication failed

      at node_modules/@pact-foundation/pact-core/src/verifier/nativeVerifier.ts:52:20

Interestingly, I've noticed that I can successfully run the Pact verification test from the backend if I use the Pact file from my local environment.
Any insights or assistance you can provide on this matter would be greatly appreciated. I'm eager to learn and resolve this issue, and your expertise would be invaluable in helping me move forward.
Thank you in advance for your time and assistance!
blobwave 1
y
Hey what does your consumer version selectors or your verifier options you pass in, look like in your test. There isn’t a provider branch set here, so that doesn’t look to be passed in from your setup
Copy code
2023-09-12T17:21:11.665825Z DEBUG ThreadId(02) pact_ffi::verifier:
 Pact source to verify = PactBrokerWithDynamicConfiguration(<http://18.237.96.220:9292/>, provider_name='customer-service', enable_pending=false, include_wip_since=None, provider_tags=["latest"], provider_branch=Some(""), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: Some("latest"), fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }], auth=Token(PACT*************)')
There is also a warning on your consumer version selectors
Copy code
WARN (39344): pact-core@14.0.4: Using the tag 'latest' is not recommended and probably does not do what you intended.
Hopefully helpful tip - You can attach logs as a snippet or use a code block (far right button on the text box) to make logs a bit easier on the eyes in future :)
s
@Yousaf Nabi (pactflow.io) Below are the options I have for Verifier
Copy code
const port = 3000
  const opts = {
    provider: "customer-service",
    logLevel: "DEBUG",
    providerBaseUrl: `<http://localhost>:${port}`,
    pactBrokerUrl: `<http://18.237.96.220:9292/>`,
    pactBrokerToken: "PACT_BROKER_TOKEN",
    consumerVersionSelectors: [{ latest: true }],
    publishVerificationResult: false,
    providerVersion: "1.0.0"
};
m
Copy code
2023-09-12T17:21:12.683471Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to <http://18.237.96.220:9292/pacts/provider/customer-service/for-verification> using POST: {"providerVersionTags":["latest"],"includePendingStatus":false,"consumerVersionSelectors":[{"tag":"latest","latest":true}],"providerVersionBranch":""}
This suggests you are specifying a tag called
latest
. Hopefully it’s not Pact JS doing something “clever”. See https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors for how selectors work and recommended default selectors. If you’re new, don’t use tags, use branches/environments.
Can you please share how you’re publishing the pact and what tags/branches etc. are on it? TL;DR - the verification selectors don’t match the contract that was published, so no pacts were found to be verified
s
Thanks for the prompt response. Here is how we are publishing the pact from consumer currently
Copy code
let projectFolder = __dirname;
let pact = require('@pact-foundation/pact-node');
let project = require('./package.json');

let options = {
  pactFilesOrDirs: [projectFolder + '/dist/pacts'],
  pactBroker: '<http://18.237.96.220:9292/>',
  consumerVersion: project.version,
  tags: ['latest']
};

pact.publishPacts(options).then(function () {
  console.log("Pacts successfully published!");
});
m
Copy code
tags: ['latest']
yeah, don’t do that 😛
“latest” is a property of a contract, I doubt the tag also needs to be it
You should publish with a branch (https://docs.pact.io/pact_broker/branches)
Also, please do ensure your
project.version
changes with each commit
s
thank you for your suggestion. Let me try all of that 🙂
🙌 1
m
You’re welcome!
For when you get to it, this is the best material for setting up your CI/CD system: howtolearn
🙏 1
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
m
^^ see the CI/CD workshop
s
@Matt (pactflow.io / pact-js / pact-go) I went through the links you shared with me and it gave me a good idea on how to setup CI/CD for Pact Testing in the build pipelines. https://docs.pact.io/pact_broker/client_cli/readme - With reference to this link, I see that there are commands which we can run from the Pact CLI to publish the pacts on the Pact Broker. Don't we have anything similar for publishing provider contract or verifying the contracts from the provider if we use OSS Pact Broker ?
m
the OSS Pact Broker doesn’t have the concept of a provider contract. I think you mean the ability to publish verification results, this is built into the verification process itself. Unlike the consumer side, it doesn’t write these results to file and then uses a CLI to publish it (perhaps it should though!). The issue above looks like a configuration issue - the selectors don’t appear to be lining up