Hello, I'm using vitest to run my consumer tests, ...
# pact-js
t
Hello, I'm using vitest to run my consumer tests, is it supported to run the tests in parallel? I'm seeing differences in contract files, that should be the same (some interactions missing) and lock file problems (only one in like 30-40 runs so far). Both might be related to parallel execution. I saw that PactV3 started supporting parallel execution and I'm using PactV4. Just want to make sure that PactV4 supports parallel execution as well.
I'm rerunning GitLab Pipeline Jobs to determine the execution time of the Contract Consumer Job and what happened is that the jobs will either A) Fail, because of a lock file issue. B) Succeed, but contain mismatching contracts in the Job Artifacts. Interactions with some endpoints are missing entirely, even though the corresponding test fails are listed as executed by vite.
m
Yes, technically V4 should be thread safe in the same way V3 is. There might be a bug of course
You would need to instantiate new `PactV4`s in each case though, and not re-use the same object
t
okay, that might be the origin of the problem. I moved the pact object to a constant to avoid doing the same configuration in each test, but I can convert it to a factory function instead.
Might this also cause the file lock problem?
m
possibly, but I believe the core engine should create and manage the locks independent of that
mind sharing the locking issues you’re having?
t
Copy code
2024-08-26T07:15:41.248673Z ERROR ThreadId(02) pact_models::file_utils: Could not acquire a shared lock on './the/place/where/the/pacts/go.json' after 3 attempts
2024-08-26T07:15:41.248801Z ERROR ThreadId(02) pact_ffi::mock_server::handles: unable to write the pact file: Could not acquire a shared lock on './the/place/where/the/pacts/go.json' after 3 attempts
[09:15:41.249] ERROR (525): The pact core was unable to write the pact file
[09:15:41.260] ERROR (525): pact-core@15.1.1: !!!!!!!!! PACT CRASHED !!!!!!!!!
The pact consumer core returned false at 'givenWithParams'. 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!
m
hmm that’s a pain. How are you setting it up exactly?
t
Do you mean Pact or the test job?
I've written a helper method
describePact
that basically acts like the
describe
in most js test frameworks, but it additionally injects an instance of the pact object into the suite. I could move the creation of this object into
describePact
, but then I would still have one object per suite, not per test. I don't know whether this is the problem, but I could create an alternative to the
it
function instead, so each case would receive its own pact object.
Just tried to disable vite's parallelsim using
--no-file-parallelism
, which seems to solve the problem with the creation of deviating contracts for now. I also added
--no-isolate
as my contract tests are stateless and the contract tests are now even faster than before.