Skip to content

fix(tests): Ensure concurrent test runs do not operate on the same BQ datasets - #2385

Open
Ford544 wants to merge 2 commits into
mainfrom
test-dataset-collision-avoidance
Open

Ford544 wants to merge 2 commits into
mainfrom
test-dataset-collision-avoidance

Conversation

@Ford544

@Ford544 Ford544 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

This fixes two classes of errors in integration tests:

  • some tests delete and recreate BQ datasets with fixed names, leading to collisions if two instances are running at the same time. This is fixed by appending a random suffix to each dataset name. Those datasets are removed at the end of each test. Because there's a risk of a dataset not being removed if the process is interrupted, the tests also remove all stale (older than 6h) datasets with matching names.
  • the two tests in tests/integration/jit.spec.ts run in parallel and shared a TmpDirFixture cleaned up in afterEach, so the test that finished first deleted the other test's project directory. When that happened before the other test's JiT step, the JiT worker couldn't find @dataform/core and the run failed with expected 'FAILED' to deeply equal 'SUCCESSFUL'. BigQuery job history shows this in 16 of 388 CI runs over the last 90 days. Fix: each test owns its project directory and removes it in finally, so tests can't delete each other's files..

@mbiernacik

Copy link
Copy Markdown
Contributor

Thanks, this is a much more complete fix than #2383. I'd like to standardise on this approach and close #2383 in favour of this PR.

There's one remaining source of flakiness that this PR doesn't cover yet:

tests/integration/jit.spec.ts: TmpDirFixture(afterEach) in a { parallel: true } suite (blocking)

TmpDirFixture registers one teardown that deletes every directory it has created. In a parallel suite, afterEach runs as soon as each test finishes. So when the first JiT test finishes, it deletes the project directory of the other test, which is still running (compiling/running from that dir). This was the other half of the JiT flake that #2383 fixed. jit.spec.ts is currently the only parallel suite in the repo that uses TmpDirFixture(afterEach).

Proposed fix (ported from #2383 to the code in this PR):

  • Each test owns its project directory (fs.mkdtempSync under TEST_TMPDIR) and its dataset (<prefix>_<uniqueSuffix>) through a withJitProject(prefix, fn) helper, and removes both in a finally. The cleanup is best effort, so a cleanup error never hides the original test failure. With that in place, the suite-level after("drop datasets") isn't needed in this file anymore. before("drop stale datasets") stays.
  • Add a comment on TmpDirFixture: in a parallel suite, pass after, not afterEach.

Nit: better failure output in jit.spec.ts

expectSuccessfulRun(runResult) passes JSON.stringify(runResult.actions) as the chai message, so a failed run shows the actual BigQuery error instead of just FAILED != SUCCESSFUL. This has been very useful for debugging the flake.

I've prepared both changes on this branch.

@Ford544
Ford544 marked this pull request as ready for review October 16, 2026 14:16
@Ford544
Ford544 requested a review from a team as a code owner October 16, 2026 14:16
@Ford544
Ford544 requested review from apilaskowski, kolina and rafal-hawrylak and removed request for a team and kolina October 16, 2026 14:16
const DATASET_METADATA_DATASET = `df_integration_test_${DATASET_METADATA_SCHEMA_SUFFIX}`;
const DATASET_METADATA_ASSERTIONS_DATASET = `df_integration_test_assertions_${DATASET_METADATA_SCHEMA_SUFFIX}`;

const DATASETS = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

DATASETS hard-codes which datasets bigquery_project creates. If the project ever writes to another dataset, that dataset is never dropped and the stale cleanup won't find it. Take the list from the compiled graph instead (the distinct target.schema of tables, assertions and operations). The same applies to evaluate.spec.ts and bigquery.spec.ts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants