Skip to content
Latchkey

Playwright "fullyParallel" Flake - Shared State Across Parallel Workers

With fullyParallel: true, Playwright runs test files - and tests within them - concurrently across workers. Tests that share a backend account, a fixed record, or global state then race each other and flake.

What this error means

Tests pass when run serially (--workers=1) but flake under full parallelism: one test deletes or mutates data another is asserting on. The failure moves between tests as worker timing shifts - the signature of shared state.

Playwright output
# passes serially
npx playwright test --workers=1            # all green

# flakes fully parallel
npx playwright test                        # FAIL: expected 1 item, got 0
# (another worker cleared the shared cart for the same user)

Common causes

Tests share a single backend account or record

Multiple workers log in as the same user or mutate the same fixed row. Concurrent writes interfere, so an assertion sees state another worker changed.

Global state not isolated per worker

A shared seed, a single storageState, or a process-global counter is mutated by parallel tests, making outcomes depend on interleaving.

How to fix it

Isolate data per worker

Create per-worker (or per-test) accounts/data with a worker-scoped fixture so parallel tests never touch the same records.

fixtures.ts
// fixtures.ts
export const test = base.extend({
  account: [async ({}, use, workerInfo) => {
    const acc = await createAccount('w' + workerInfo.workerIndex);
    await use(acc);
    await deleteAccount(acc.id);
  }, { scope: 'worker' }],
});

Serialize only what truly must be serial

  1. Use test.describe.serial() for a small group that legitimately shares order.
  2. Give each test its own seeded data rather than a shared fixed record.
  3. Reproduce locally with full workers (not --workers=1) to expose the coupling.

How to prevent it

  • Provision per-worker accounts/data via worker-scoped fixtures.
  • Avoid shared fixed records across parallel tests.
  • Run full-parallel in CI so coupling surfaces early.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →