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

fix(snapshot): fix concurrent SnapshotClient.startCurrentRun with same filepath #4793

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Dec 22, 2023

Description

(EDIT: I made an alternative PR in #4796, which makes more sense to me, but have a little more moving parts.)

Closes #4782
Closes #3361

It seems there is a slight race condition when running multiple SnapshotClient.startCurrrentRun + assert concurrently while each run is synchronous.

Note that this all-synchronous case is not covered by the existing test, such as:

data.forEach((i) => {
test.concurrent(i, async ({ expect }) => {
await new Promise(resolve => setTimeout(resolve, Math.random() * 100))
expect(i).toMatchSnapshot()
})
})

The issue is similar to Time-of-check to time-of-use race condition. So, running Map.get/set synchronously ensures SnapshotClient to have unique SnapshotState per filepath.

Though I think this works as a quick fix, the underlying issue might be that VitestTestRunner's current usage of SnapshotClient where SnapshotClient is not designed to run concurrently. I'm exploring a better approach to deal with issue, but if maintainers are happy with current fix, then larger restructuring might not be necessary.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Dec 22, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 58528e7
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/658527120190240008cf3551

@hi-ogawa hi-ogawa force-pushed the fix-snapshot-concurrent-startCurrentRun branch from 425cd18 to ef3d07e Compare December 22, 2023 01:27
@hi-ogawa hi-ogawa marked this pull request as ready for review December 22, 2023 04:01
Comment on lines +18 to +21
await generateInlineTest(
resolve(dir, './inline-test-template-concurrent.js'),
resolve(dir, '../test-update/inline-test-template-concurrent.test.js'),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is mostly taken from #4783. Thanks @martypdx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant