Skip to content

test(core): fix the flaky database transactions and collection filter e2e tests - #5788

Open
dlhck wants to merge 2 commits into
majorfrom
dhoeck/plat-753-fix-the-flaky-database-transactions-and
Open

dlhck wants to merge 2 commits into
majorfrom
dhoeck/plat-753-fix-the-flaky-database-transactions-and

Conversation

@dlhck

@dlhck dlhck commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes two core e2e tests that fail at random on CI and pass on a re-run. Both are test problems, so I made no core change.

database-transactions.e2e-spec.ts: concurrent writes in withTransaction()

Seen on major and on PRs into it (MySQL): runs 43024393448, 43025720370 and 43232946603. The test "failing mutation inside connection.withTransaction() wrapper with context and promise concurrent execution" failed with expected 4 to be 3. The two tests after it then failed too, because the extra row stays in the database.

Cause. The createNTestAdministrators2 test mutation starts 10 writes inside withTransaction(), 10 ms apart, and returns Promise.all(). The first failing write rejects Promise.all(), so withTransaction() rolls back and releases the query runner while other writes are still running. A write that the driver queues on the connection after the ROLLBACK runs outside the transaction, and the database keeps its row. On a fast host the rollback ends before the next write starts, so later writes fail with "Query runner already released" and nothing leaks. On a slow runner the rollback overlaps writes that are still running.

Fix. The work function now waits for all writes to settle before it returns or throws, so the rollback includes every write. This matches the @Transaction() variant of the same test, which already waits. The expected error is now always Failed!, so the test no longer accepts "Query runner already released".

Reproduction. I used a temporary spec (not committed) that calls the mutation 40 times and counts leaked user rows. To get the same overlap as on a slow runner, the gap between writes was 1 ms instead of 10 ms:

MySQL 8 Postgres 16
Before the fix 20 of 40 calls leaked rows 16 of 40 calls leaked rows
After the fix 0 of 40 0 of 40

collection.e2e-spec.ts: awaitRunningJobs timeout

Seen in runs 42792699214 (Postgres and MySQL) and 42800763951 (MySQL). The test "combining an AND-ed and an OR-ed filter > does not duplicate variants pulled in by the OR-ed filter when they have multiple translations" failed with awaitRunningJobs timed out after 5000ms.

Cause. The test runs six product and variant mutations before it creates the collection, and each one queues an apply-collection-filters job for all Collections. The queue runs the jobs one at a time and takes the next one about 200 ms after the previous one ends. On an idle host, Postgres needs 2.6 s for this test's jobs. With the Postgres container limited to 0.1 CPU it needs 4.5 s, and with 0.05 CPU it needs 12.6 s. At 0.05 CPU the unchanged test fails with the CI error (timed out after 5000ms with 6 job(s) still running). The jobs it leaves behind then also make the next test time out.

Fix. The test waits up to 20 seconds. awaitRunningJobs() returns as soon as the queue is empty, so a fast run does not wait longer. With the fix, the whole spec passes at 0.05 CPU.

Proof

20 consecutive local runs, with CI=true and the database images and settings from the CI workflow:

  • database-transactions.e2e-spec.ts: 20 of 20 on Postgres 16, 20 of 20 on MySQL 8.
  • collection.e2e-spec.ts: 20 of 20 on Postgres 16.

Breaking changes

None. Test changes only.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…t rolls back

The createNTestAdministrators2 test mutation starts 10 writes in
withTransaction() and returned Promise.all(). The first failure rejected
Promise.all, so withTransaction() rolled back and released the query
runner while other writes were still running. A write queued on the
connection after the ROLLBACK ran outside the transaction, and the
database kept its user row. The test then counted one user too many,
and the next tests of the suite failed with the same extra row.

The work function now waits for all writes to settle before it returns
or throws, so the rollback includes every write. The error that the
test expects is now always "Failed!".
…s jobs

The test runs six product and variant mutations, and each one queues an
apply-collection-filters job for all Collections. The job queue runs the
jobs one at a time, so on a slow runner the jobs need more than the
5 seconds that the test waited. The test now waits up to 20 seconds.
awaitRunningJobs() returns when the queue is empty, so a fast run does
not wait longer.
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
vendure-storybook Ready Ready Preview Nov 14, 2026 8:32am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

Dashboard Preview: https://admin-dashboard-jt6hdzx70-vendure.vercel.app

@sonarqubecloud

Copy link
Copy Markdown

@dlhck
dlhck marked this pull request as ready for review November 14, 2026 09:03

This branch was successfully deployed

1 active deployment
Preview — c7f7cb30 Deployed Nov 14, 2026 by vercel[bot]
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.

1 participant