Hiya folks :wave: I hope you are doing well :slig...
# pact-js
m
Hiya folks ๐Ÿ‘‹ I hope you are doing well ๐Ÿ™‚ I am looking for some help with my PactJs implementation. Context I am trying to assert if Contract Testing can be used to strengthen Developer Confidence. I have setup PactJs between 2 services as a test candidate. Problem Statement While the local Contract Testing is working fine by sharing the Pact locally between to the Provider, I am having some difficulties with the Pact Broker. I am using PactFlow as the broker. Here is a snippet of how I am setting my
VerifierOptions
in my provider test:
Copy code
baseOptions = {
			providerBaseUrl: appUrl,
			provider: 'SDS',
			log: path.resolve( process.cwd(), 'logs', 'pact.log' ),
			// pactUrls: [ path.resolve( __dirname, '../pacts/SDS-Parker.json' ) ],
			logLevel: 'trace' as LogLevel,
			
			// Fetching the pact from broker
			pactBroker: 'https://<orgName>.<http://pactflow.io|pactflow.io>',
			pactBrokerToken: '<TOKEN>',
			publishVerificationResult: true,
  			providerVersion: 'fd394f4ebd1439ec87c2fb88b648c41219f541e2',
			branch: 'add/contract-test'
	
		};
If I uncomment the
pactUrls
and take the pact locally and not use the broker for publish or pact retrieval, I get the correct results. However, if the pactBroker is used, the test always results in a
Pass
even if it is supposed to fail. Also, when using the pact broker, the test results do not show the โ€œinteraction wiseโ€ results. Instead they show the following:
Copy code
PASS  test/contract/parker/blog.contract-spec.ts (34.145 s)ifier: @param handle = 0x400b712400
  pact Verification
    โœ“ should validate Parker expectations (1191 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        34.839 s, estimated 51 s
Ran all test suites.
Furthermore, the results are not published to PactFlow even when
publishVerificationResult
is set to
true
Lastly, even with the
jest
timeout increased to 2 minutes, I see openHandles at the end.
Copy code
[18:27:01.626] TRACE (117): pact@10.4.1: Verification completed, closing server

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  โ—  WORKER

      70 |
      71 |      it( 'should validate Parker expectations', async () => {
    > 72 |              const verifier = new Verifier( baseOptions );
         |                               ^
      73 |              await verifier.verifyProvider();
      74 |      } );
      75 | } );
๐Ÿ‘‹ 1
To publish the pacts, I am using
pact
from
@pact-foundation/pact-core
Copy code
pact.publishPacts( opts ).then( ( err, res ) => {
		if ( err ) {
			throw new Error( `Error while publishing pacts to the broker: ${ err }` );
		} else {
			console.log( res );
		}
	} );
} );
The pact is correctly published by the consumer at PactFlow
Moreover, I have setup the provider name correctly in the consumer tests:
Copy code
const provider = new PactV3( {
	consumer: 'Parker',
	provider: 'SDS',
	port: 4000,
	logLevel: 'INFO',
} );
I am hoping to find what I could be doing wrong. Also, if there was a mismatch or any incorrectness in the pact, why would provider test result in
Pass
but not actually run the proper tests (I am sure of this because I changed the conditions to ensure the test should fail. which is does if the pact is shared locally)
Please feel free to redirect me to the pact-broker channel if you think this does not belong here
m
Can you please share the debug logs? That will help us answer the q
There is an open issue regarding handles, it seems to be related to the underlying log library
My guess is that it's not finding the contract, and therefore not verifying anything, hence why you're not seeing any test output
m
Thanks for getting back, Matt ๐Ÿ™‚ Here are the debug logs:
Copy code
2023-02-18T09:06:16.043221Z DEBUG ThreadId(02) pact_plugin_driver::plugin_manager: Shutting down all plugins
2023-02-18T09:06:16.044952Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERR PASS  test/contract/parker/blog.contract-spec.ts (30.72 s)
  pact Verification
    โœ“ should validate Parker expectations (562 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        31.286 s, estimated 32 s
Ran all test suites.
[09:06:15.610] INFO (36): pact@10.4.1: Verifying provider
[09:06:15.735] DEBUG (36): pact-core@13.13.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
[09:06:15.631] INFO (36): pact@10.4.1: debug request/response logging enabled
[09:06:15.670] INFO (36): pact-core@13.13.4: Verifying Pacts.
[09:06:15.679] INFO (36): pact-core@13.13.4: Verifying Pact Files
[09:06:15.679] DEBUG (36): pact-core@13.13.4: Initalising native core at log level 'debug'
[09:06:15.746] DEBUG (36): pact-core@13.13.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
[09:06:15.747] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided
[09:06:15.747] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided
[09:06:15.748] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierBrokerSourceWithSelectors' was not executed as it had non-fatal validation errors: No pactBrokerUrl option / PACT_BROKER_BASE_URL set, or no provider option set
[09:06:15.748] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided
[09:06:16.067] DEBUG (36): pact-core@13.13.4: shutting down verifier with handle 0
[09:06:16.069] DEBUG (36): pact-core@13.13.4: response from verifier: null, 0
[09:06:16.069] INFO (36): pact-core@13.13.4: Verification successful

Jest has detected the following 2 open handles potentially keeping Jest from exiting:

  โ—  WORKER

      78 |
      79 |      it( 'should validate Parker expectations', async () => {
    > 80 |              const verifier = new Verifier( baseOptions );
         |                               ^
      81 |              await verifier.verifyProvider();
      82 |      } );
      83 | } );

      at createWorker (../node_modules/thread-stream/index.js:52:18)
      at new ThreadStream (../node_modules/thread-stream/index.js:224:19)
      at buildStream (../node_modules/pino/lib/transport.js:21:18)
      at transport (../node_modules/pino/lib/transport.js:114:10)
      at normalizeArgs (../node_modules/pino/lib/tools.js:311:16)
      at pino (../node_modules/pino/pino.js:87:28)
      at createLogger (../node_modules/@pact-foundation/pact-core/src/logger/pino.ts:5:7)
      at setLogLevel (../node_modules/@pact-foundation/pact-core/src/logger/index.ts:18:24)
      at Pact.logLevel (../node_modules/@pact-foundation/pact-core/src/pact.ts:50:23)
      at new Verifier (../node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:35:22)
      at Object.<anonymous> (contract/parker/blog.contract-spec.ts:80:20)


  โ—  WORKER

      78 |
      79 |      it( 'should validate Parker expectations', async () => {
    > 80 |              const verifier = new Verifier( baseOptions );
         |                               ^
      81 |              await verifier.verifyProvider();
      82 |      } );
      83 | } );

      at createWorker (../node_modules/thread-stream/index.js:52:18)
      at new ThreadStream (../node_modules/thread-stream/index.js:224:19)
      at buildStream (../node_modules/pino/lib/transport.js:21:18)
      at transport (../node_modules/pino/lib/transport.js:114:10)
      at normalizeArgs (../node_modules/pino/lib/tools.js:311:16)
      at pino (../node_modules/pino/pino.js:87:28)
      at createLogger (../node_modules/@pact-foundation/pact-core/src/logger/pino.ts:5:7)
      at setLogLevel (../node_modules/@pact-foundation/pact-core/src/logger/index.ts:18:24)
      at new Verifier (../node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:36:18)
      at Object.<anonymous> (contract/parker/blog.contract-spec.ts:80:20)
The logs print
Verification successful
though. Also, I tried adding the VerifierOpts like
failIfNoPactsFound:true
but the results do not change with that
I wish there was a way to find out if the verifier was even going to my PactFlow broker to fetch the logs. However, I could not find any audit/access logs feature in PactFlow that would determine that the test is trying to access remote pact
Hey Matt! Following your suspicion, I further dug into the debug logs and on a hunch I set the
PACT_BROKER_BASE_URL='https://<mybroker>.<http://pactflow.io|pactflow.io>'
in environment while running the tests. And, voila! the results are now being published to the broker ๐ŸŽ‰ There are 3 concerns here: 1. Why the
providerBaseUrl
in verifier options not being honoured? 2. If the pacts were not found, how come we are printing the success status 3. I am still seeing some
openHandles
at the end of the test, even with Jest timeout increased to 5 minutes or so. I have to
--forceExit
at the end. Is this known? Nonetheless, thanks a lot for the help here. Now, I can move onto
can-i-deploy
experiments and tests.
m
1. That URL is the URL of your provider, not the broker.
pactBrokerUrl
is the correct broker url, you have set it to
pactBroker
(the property is ignored) 2. No pacts found is not an error 3. There are a few open issues about this, we believe due to a dependency. e.g https://github.com/pact-foundation/pact-js/issues/1033
m
Thanks for the confirmation, Matt. This really helps and I advances me to the next step of integrating the
can-i-deploy
workflow. Sorry about the confusion in the below
1. Why the
providerBaseUrl
in verifier options not being honoured?
I wanted to say that I had provided the
pactBrokerUrl
in VerifierOptions. However, It turns out that instead of providing
pactBrokerUrl
, I was trying to supply
pactBroker
. I feel so stupid to not do type checking and wrangling at this issue improperly. Although, in the process, I learnt a lot about Pact so that is a win ๐Ÿ™‚ I will checkout the linked issues for other queries.
Many thanks ๐Ÿ’™
๐Ÿ™Œ 1
m
Haha no worries at all, we all do that sometimes! You're welcome!
d
hi! iโ€™m also getting
connection error error=GoAway
๐Ÿ˜ž
Copy code
"@pact-foundation/pact": "10.4.1",