Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3] File locking issue when writing to pact file with parallel tests in Jest #599

Closed
3 of 5 tasks
mefellows opened this issue Feb 7, 2021 · 10 comments
Closed
3 of 5 tasks
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@mefellows
Copy link
Member

mefellows commented Feb 7, 2021

Software versions

Please provide at least OS and version of pact-js

  • OS: Mac OSX 10.15.7
  • Consumer Pact library: 10.0.0-beta.29
  • Provider Pact library: n/a
  • Node Version: v12.18.0 (node) / 6.14.4 (npm)

Issue Checklist

Please confirm the following:

  • I have upgraded to the latest
  • I have the read the FAQs in the Readme
  • I have triple checked, that there are no unhandled promises in my code
  • I have set my log level to debug and attached a log file showing the complete request/response cycle
  • For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem

Expected behaviour

Pact file is written correctly when tests are run in parallel.

Actual behaviour

  • I have 6 tests and launch them in parallel by jest
  • In 50% cases it false with error:
  • (line and column numbers are different each launch)
  • If I launch jest in one worker – no such an error. Looks like it is a kind of race condition.

Failure notice:

Failed to write pact to file - Failed to parse Pact JSON - EOF while parsing a string at line 386 column 20

The error seems to be this.pact.writePactFile(result.mockServer.id, this.opts.dir) // src/v3/pact.ts:208:23, and likely is a file locking issue.

Steps to reproduce

cd examples/v3/e2e
npm i --save-dev jest
cp test/consumer.spec.js test/consumer2.spec.js 
cp test/consumer.spec.js test/consumer3.spec.js 
cp test/consumer.spec.js test/consumer4.spec.js
jest test/*.spec.js
@mefellows mefellows added the bug Indicates an unexpected problem or unintended behavior label Feb 7, 2021
@TimothyJones
Copy link
Contributor

In on mobile, but the documentation says somewhere that tests need to be run with —runInBand. We might need to surface that more clearly.

Of course, if we can fix it, that would be even better.

@mefellows
Copy link
Member Author

Yes we do indeed! But that's only for the current package, the v3 package should be allowed to do this

@mefellows
Copy link
Member Author

from mock_server.rs:

Screen Shot 2021-02-08 at 10 12 00 am

It seems the original author could foresee this issue :)

@TimothyJones
Copy link
Contributor

I believe this issue will happen with any framework that parallelises tests- but Jest is the only one I am aware of.

I wanted to get jest-pact to detect whether the tests were running in parallel and warn, but I couldn’t figure out a way to determine it

@TimothyJones
Copy link
Contributor

Oh, I didn’t see this was v3

@TimothyJones
Copy link
Contributor

A coworker and I once chased a broken feature down to a function that said “todo: implement this method”. So I guess this is better ;)

@mefellows
Copy link
Member Author

Ron, I can see you've been making some changes for this. I was also but haven't pushed. I'll leave the upstream lib changes for you, want me to push the updates to the JS side? FYI it was fairly easy to replicate by just duplicating more tests.

@uglyog
Copy link
Member

uglyog commented Feb 8, 2021

Rust libs have been released

@TimothyJones TimothyJones added the v3 label Feb 8, 2021
@TimothyJones TimothyJones changed the title File locking issue when writing to pact file with parallel tests in Jest [V3] File locking issue when writing to pact file with parallel tests in Jest Feb 8, 2021
mefellows added a commit that referenced this issue Feb 8, 2021
- Adds overwrite flag to consumer tests to control pact write behaviour
- Adds callbackTimeout on provider side to control provider states and
request filter execution timeout
- Fixes file locking issues #599
- Fixes #600
@TimothyJones
Copy link
Contributor

@mefellows Do you know if this can be closed now?

@mefellows
Copy link
Member Author

Yes, I believe it has been fixed - thanks and closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants