Hi all, what could be the reason for the following...
# pact-js
m
Hi all, what could be the reason for the following error
Copy code
2023-06-13T20:59:16.333720Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (165 bytes)
2023-06-13T20:59:16.333735Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-06-13T20:59:16.333768Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.334098Z ERROR ThreadId(02) pact_verifier: Failed to load pact - Could not load pacts from the pact broker '<http://localhost:9292>'
2023-06-13T20:59:16.334130Z  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'.
basically 1. I downloaded a branch from my coworker, 2. I ran the consumer tests, 3. I published the contract into the broker (local docker, no previous version of the contract), 4. run the provider test and it was throwing the error about couldn’t not load pacts
m
Please share the debug logs, the code you use to select pacts (i.e. verification code) or both
m
Copy code
> e2e@1.0.0 test:provider
> mocha test/provider.spec.js

People App Service listening on <http://localhost:8081>


  Pact Verification
2023-06-13T20:59:15.734805Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked
2023-06-13T20:59:15.735309Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked
2023-06-13T20:59:15.735513Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_state FFI function invoked
2023-06-13T20:59:15.735639Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked
2023-06-13T20:59:15.735716Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_publish_options FFI function invoked
2023-06-13T20:59:15.736158Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked
2023-06-13T20:59:15.739750Z DEBUG ThreadId(02) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_execute FFI function invoked
2023-06-13T20:59:15.739824Z DEBUG ThreadId(02) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(<http://localhost:9292>, provider_name='e2e Provider Example', enable_pending=true, include_wip_since=None, provider_tags=["master"], provider_branch=Some("master"), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: Some(true) }], auth=None')
2023-06-13T20:59:15.743652Z 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-06-13T20:59:15.743713Z 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
[14:59:15.735] DEBUG (90906): pact-core@13.13.5: 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
[14:59:15.725] INFO (90906): pact@11.0.2: Verifying provider
[14:59:15.735] DEBUG (90906): pact-core@13.13.5: 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
[14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierSetFailIfNoPactsFound' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided
[14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided
[14:59:15.736] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided
[14:59:15.736] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided
[14:59:15.732] INFO (90906): pact-core@13.13.5: Verifying Pacts.
[14:59:15.733] INFO (90906): pact-core@13.13.5: Verifying Pact Files
[14:59:15.733] DEBUG (90906): pact-core@13.13.5: Initalising native core at log level 'DEBUG'
2023-06-13T20:59:16.281088Z  INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/' from pact broker
2023-06-13T20:59:16.281462Z DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="localhost"
2023-06-13T20:59:16.282985Z DEBUG ThreadId(02) hyper::client::connect::http: connecting to [::1]:9292
2023-06-13T20:59:16.283349Z DEBUG ThreadId(02) hyper::client::connect::http: connected to [::1]:9292
2023-06-13T20:59:16.283928Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 155 bytes
2023-06-13T20:59:16.293714Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-06-13T20:59:16.293743Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (4300 bytes)
2023-06-13T20:59:16.293784Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-06-13T20:59:16.293815Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.294215Z DEBUG ThreadId(02) pact_verifier::pact_broker: Link URL is templated
2023-06-13T20:59:16.294306Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = <http://localhost:9292/pacts/provider/{provider}/for-verification>
2023-06-13T20:59:16.295418Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = <http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification>
2023-06-13T20:59:16.295499Z  INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/pacts/provider/e2e%20Provider%20Example/for-verification' from pact broker
2023-06-13T20:59:16.295528Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.295610Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 211 bytes
2023-06-13T20:59:16.318444Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-06-13T20:59:16.318464Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (2554 bytes)
2023-06-13T20:59:16.318482Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-06-13T20:59:16.318508Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.318690Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = <http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification>
2023-06-13T20:59:16.319412Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = <http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification>
2023-06-13T20:59:16.319474Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to <http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification> using POST: {"providerVersionTags":["master"],"includePendingStatus":true,"consumerVersionSelectors":[{"matchingBranch":true}],"providerVersionBranch":"master"}
2023-06-13T20:59:16.319515Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.319607Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 421 bytes
2023-06-13T20:59:16.333702Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-06-13T20:59:16.333720Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (165 bytes)
2023-06-13T20:59:16.333735Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed
2023-06-13T20:59:16.333768Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292)
2023-06-13T20:59:16.334098Z ERROR ThreadId(02) pact_verifier: Failed to load pact - Could not load pacts from the pact broker '<http://localhost:9292>'
2023-06-13T20:59:16.334130Z  WARN ThreadId(02) pact_matching::metrics:
Copy code
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-06-13T20:59:16.337991Z DEBUG ThreadId(02) pact_matching::metrics: Sending event to GA - {"tid": "UA-117778936-1", "cid": "21f374b6ee8766d5fa78d27c9b22ecfb", "av": "13.13.5", "an": "pact-core", "aip": "true", "t": "event", "cd6": "pact_ffi", "cd7": "1.0.4", "aid": "pact-core", "v": "1", "ds": "client", "cd2": "unknown", "ec": "ProviderTest", "cd3": "macos-x86_64", "el": "Pacts verified", "ea": "Completed", "ev": "0"}
2023-06-13T20:59:16.714840Z DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="<http://www.google-analytics.com|www.google-analytics.com>"
2023-06-13T20:59:16.806869Z DEBUG ThreadId(02) hyper::client::connect::http: connecting to 216.239.36.178:443
2023-06-13T20:59:16.874056Z DEBUG ThreadId(02) hyper::client::connect::http: connected to 216.239.36.178:443
2023-06-13T20:59:16.957343Z DEBUG ThreadId(02) h2::client: binding client connection
2023-06-13T20:59:16.957394Z DEBUG ThreadId(02) h2::client: client connection bound
2023-06-13T20:59:16.957428Z DEBUG ThreadId(02) h2::codec::framed_write: send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
2023-06-13T20:59:16.957677Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("https", <http://www.google-analytics.com|www.google-analytics.com>)
2023-06-13T20:59:16.957687Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 }
2023-06-13T20:59:16.958342Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) }
2023-06-13T20:59:16.958401Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) }
2023-06-13T20:59:17.034767Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x0), max_concurrent_streams: 100, initial_window_size: 1048576, max_header_list_size: 65536 }
2023-06-13T20:59:17.034815Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Settings { flags: (0x1: ACK) }
2023-06-13T20:59:17.034832Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=WindowUpdate { stream_id: StreamId(0), size_increment: 983041 }
2023-06-13T20:59:17.095060Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x1: ACK) }
2023-06-13T20:59:17.095096Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::settings: received settings ACK; applying Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
2023-06-13T20:59:17.118661Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) }
2023-06-13T20:59:17.118723Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1) }
2023-06-13T20:59:17.118746Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) }
2023-06-13T20:59:17.118759Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Ping { ack: false, payload: [0, 0, 0, 0, 0, 0, 0, 0] }
2023-06-13T20:59:17.118768Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Ping { ack: true, payload: [0, 0, 0, 0, 0, 0, 0, 0] }

Failures:

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


There were 1 pact failures

2023-06-13T20:59:17.119083Z DEBUG ThreadId(02) pact_plugin_driver::plugin_manager: Shutting down all plugins
2023-06-13T20:59:17.119132Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=GoAway { error_code: NO_ERROR, last_stream_id: StreamId(0) }
2023-06-13T20:59:17.119161Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERROR, Library)
2023-06-13T20:59:17.120102Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_shutdown FFI function invoked
    1) validates the expectations of Matching Service


  0 passing (1s)
  1 failing

  1) Pact Verification
       validates the expectations of Matching Service:
     Error: Verfication failed
t
That example doesn’t use a local broker, so presumably you’ve changed it somewhat
Is your broker running?
m
yes, it’s running
I published the contract and then I ran the provider tests
m
My guess is the consumer contract is not tagged, and is not matching the selectors
Copy code
<http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification> using POST: {"providerVersionTags":["master"],"includePendingStatus":true,"consumerVersionSelectors":[{"matchingBranch":true}],"providerVersionBranch":"master"}
That says “find pacts in the broker that have a matching branch (
master
)”
Is the consumer contract tagged with the
master
branch?
m
sorry, I was away…
is the branch name affecting this?
t
Yes. The example you are looking at is selecting the branch as master
m
so, line 58 should be something like
Copy code
process.env.GIT_BRANCH || 'master',
t
No, that line is about what to tag the provider with
Line 59 is the one you need to update, to get the branch from git or whatever you use
m
I just put the branch name hardcoded and it worked… I’m wondering why it was working before in another branch
t
I would guess that
GIT_BRANCH
is not set by your CI, so you're getting the default of
'master'
really that example should be updated to not hard code that bit.
👍 1
m
anyway, you guys helped me to point out the issue 👍
t
but it's hard to produce a universal example, because what if they're not using git
m
Hi again, is this a valid solution? or is there a better way to do get the branch name?
Copy code
import { exec } from 'child_process';

const getBranch = () => new Promise((resolve, reject) => {
    return exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) => {
        if (err)
            reject(`getBranch Error: ${err}`);
        else if (typeof stdout === 'string')
            resolve(stdout.trim());
    });
});

export { getBranch }
Copy code
// --- --- Another File / Module --- ---
import { getBranch } from './moduleLocation.mjs'

const someAsyncFunction = async () => {
  console.log(await getBranch()); 
}

someAsyncFunction();
t
Usually you would get it from an environment variable that is set automatically by your CI
m
that’s what I thought, but how can I run the provider tests locally... or am I misunderstanding the workflow?
or should I replace the branch name manually every time I wanna run the tests locally?
t
I don’t personally use the matching branch thing, I’m not sure how it’s supposed to work in that case
I think matching branch is for when you want the consumer and the provider’s feature branches to be named the same. I’m not sure why it’s in that example
m
ok, so if that’s the case I think I can get rid of it
I’m gonna use the
Copy code
pactUrls: [...]
that solves my issue
m
So Moises doing that is not ideal - you do really want to pull dynamically from the broker
See the ci/cd workshop 👇 (howtolearn) for a lab on how to achieve a solid pipeline setup
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
the get branch thing above should be fine.
It’s a reminder - we should aim to pull that automatically from the verifier. I’ll raise a feature request
m
thanks @Matt (pactflow.io / pact-js / pact-go), so does that mean that it’s ok if we create a ‘getBranch’ function as a workaround to get it locally… currently we are starting with the contract test, we don’t have the ci/cd implemented yet, we are running the tests locally (docker locally). The goal is to implement the ci/cd later
I heading out, but I’ll check later when I go back
back