pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.61k stars 344 forks source link

PACT CRASHED #971

Closed ghsouza89 closed 2 months ago

ghsouza89 commented 1 year ago

Thank you for reporting a bug! We appreciate it very much. Issues are a big input into the priorities for Pact development

All italic text in this template is safe to remove before submitting

Thanks again!

Software versions

Please provide at least OS and version of pact-js

Issue Checklist

Please confirm the following:

Expected behaviour

No error message should be displayed

Actual behaviour

`[2022-11-08 20:43:00.007 +0000] ERROR (21300 on Ghsouza): pact-core@13.11.0: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'withResponseHeader'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!`

Steps to reproduce

How can someone else reproduce this bug?

  1. clone this repo >>> https://github.com/Ghsouza1/poc-contract-testing
  2. got to test folder
  3. run: npm install
  4. npm run test

For extra bonus points and internet karma, provide a repository, gist or reproducible code snippet so that we can test the problem.

repo: https://github.com/Ghsouza1/poc-contract-testing

We recommend forking the project and modifying a relevant example in the examples folder

Relevant log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link to a gist). image

mefellows commented 1 year ago

Thanks for the report and for the repro!

First up, there is at least a few logic errors in the test, here is a diff to get the sequence working as needed (the tests will fail, but for the right reasons):

diff --git a/test/service.spec.ts b/test/service.spec.ts
index 55e6d02..0726fc1 100644
--- a/test/service.spec.ts
+++ b/test/service.spec.ts
@@ -258,10 +258,13 @@ describe("The planets API", () => {
   const EXPECTED_BODY_LIST = eachLike(planetsListExample);

   beforeAll(() =>
-    provider.setup().then(() => {
-      planetService = new PlanetService({ url });
+    provider.setup().then((mockservice) => {
+      planetService = new PlanetService({ url: `http://${mockservice.host}:${mockservice.port}` });
     })
   );
+
+   afterEach(() => provider.verify())
+
   describe("get a single /planets/{id}", () => {
     beforeAll(() => {
       const interaction = new Interaction()

There is a bug though (probably in Pact JS), which is that it's not clearing the interactions.

If you're new to Pact, I'd suggest using the PactV3 interface as it's designed to better guard against this, but I'll leave the bug label open.

animeshkumar29 commented 3 months ago

Hi Team Noticed this issue in my Environment also , can someone please help to resolve this issue or help with some work around , Main problem is i have created Pact Setup and Pact interaction method dynamically and when i am calling with single test its passing without any issue , but when i am calling with two test , my first test is passing and my Second test is failing ,

Adding implementation code and Error response Implantation Code `const pactConfig = { consumer: 'YourConsumer', provider: 'YourProvider', port: 1234, log: './logs/pact.log', dir: './pacts', };

const pact = new Pact(pactConfig); export async function startPactServer() { await pact.setup();

} export async function intractPactServer(state:string,uponReceiving:string,method:HTTPMethods,statusCode:number,resource:string,filePath:string) { await pact.addInteraction({ state: state, uponReceiving: uponReceiving, withRequest: { method: method, path: resource, }, willRespondWith: { status: statusCode, body: await nilgirihub.readJSONfile(filePath), }, }); }

export async function stopPactServer() { await pact.finalize(); } **Error** [02:40:10.061] ERROR (2669): pact-core@14.3.6: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'uponReceiving'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!

[02:40:10.062] ERROR (2669): pact-core@14.3.6: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'given'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!

[02:40:10.062] ERROR (2669): pact-core@14.3.6: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'withRequest'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!

[02:40:10.062] ERROR (2669): pact-core@14.3.6: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'withStatus'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!

[02:40:10.063] ERROR (2669): pact-core@14.3.6: !!!!!!!!! PACT CRASHED !!!!!!!!!

The pact consumer core returned false at 'withResponseBody'. This should only happen if the core methods were invoked out of order

This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.

There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output.

SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world.

We're sorry about this!`

mefellows commented 3 months ago

See above workaround. Use the newer V3 or V4 interface