Skip to content

[Feature]: Allow retryStrategy: 'isolated' in test.describe.configure() for tests requiring zero background workers #43351

Closed

Description

🚀 Feature Request

Playwright recently introduced retryStrategy: 'isolated', however, it is currently restricted to the global testConfig. It'd be very helpful if retryStrategy was implemented at the test file level in test.describe.configure() so isolated retries can be targeted only to tests that require zero concurrency to pass.

Existing features do not solve this

  1. Why lock doesn't work:
    lock is an opt-in named mutex, not a runner-wide exclusive lock:
    If Test A has { lock: 'foo' }, it only blocks other tests that also declare { lock: 'foo' }.
    All other unlocked tests in the repository still run concurrently in background workers alongside Test A.
    To achieve true isolation with lock, we would have to add { lock: 'foo' } to every single test in the entire codebase, which would completely eliminate parallel execution for the whole test run.
  2. Why global retryStrategy: 'isolated' in playwright.config.ts is insufficient:
    It is currently an all-or-nothing global flag.
    It forces every failed test across thousands of unrelated files to defer its retries to the single-worker tail phase, even if 99% of tests are completely stateless and should just retry immediately.

Example

import { test, expect } from '@playwright/test';

// Only this suite will be retried in isolation if concurrency causes a failure
test.describe.configure({
  retries: 1,
  retryStrategy: 'isolated',
 });

test.describe('tests that fail under concurrent execution', () => {
  test('exclusive test', async ({ page }) => {
    /* Runs in parallel initially.
    If it collides with another worker and fails, it is retried
    at the end of the run with no other tests running concurrently. */
  });
});

Expected Behaviour:

Global/default retry strategy remains 'immediate' (or whatever is set in playwright.config.ts).
Test files configured with override, retryStrategy: 'isolated' at the test.describe level are queued to run in isolation (one worker, no other concurrent tests running) upon failure.

Motivation

We have specific tests that require zero-concurrency isolation (meaning no other worker threads can be running anywhere in the runner at the same time) to pass as the nature of these tests make them extremely vulnerable to cross-test interference. We want our test suite to run in parallel by default but if these specific tests fail under concurrency, we want their retries to run in isolation without background workers.

Activity

  1. alok-108 commented on Oct 13, 2026

    @alok-108
    Contributor

    +1, this would be super useful. Having retryStrategy: 'isolated' only as a global config option is pretty restrictive when only a handful of heavy/stateful tests actually collide under concurrency.

    Since retries, timeout, and mode can already be configured per-suite in test.describe.configure(), supporting retryStrategy there feels like a natural fit. In the dispatcher (dispatcher.ts), it would just be checking test._retryStrategy ?? config.retryStrategy when sorting failed tests into isolatedRetriesJob vs remaining.

  2. alok-108 commented on Oct 13, 2026

    @alok-108
    Contributor

    If the maintainers are open to supporting this, feel free to assign it to me
    I'd love to take this on, dig deeper into the runner edge cases, and put together a PR with tests.

  3. yury-s commented on Oct 13, 2026

    @yury-s
    Member

    Hi, the Playwright bot looked into this on my behalf. This asks for the same thing as #43194, which was closed. You can already get full isolation for these tests, on the first attempt as well as on retries, by moving them to a separate project that depends on the rest and uses one worker:

    // playwright.config.ts
    export default defineConfig({
      fullyParallel: true,
      projects: [
        { name: 'main', testIgnore: /exclusive/ },
        { name: 'exclusive', testMatch: /exclusive/, dependencies: ['main'], workers: 1 },
      ],
    });

    exclusive starts only after every main test has finished, and runs its tests one at a time, with retries as usual. I checked this on tip-of-tree with 4 workers: the first exclusive test started after the last main test ended, and the next one started after it finished.

    Investigated locally by the Playwright bot

  4. yury-s commented on Oct 14, 2026

    @yury-s
    Member

    One missing piece is failFast on the project main, so that we if it fails the dependency project still runs.

  5. toduyemi commented on Oct 14, 2026

    @toduyemi
    Author

    Yury Semikhatsky (@yury-s) Thanks for reopening and exploring this. While seperate projects works locally, dependencies: ['main] doesn't work in CI where we --shard our tests. I already attempted something similar because I agree, running these exclusive tests serially from the start is the ideal scenario.

    Playwright treats project dependencies as un-sharded prerequisites. Any shard that gets assigned tests from exclusive will execute the entire main project from start to finish before running exclusive. If tests from exclusive are distributed across shards, main ends up being duplicated on each of those shards, significantly multiplying CI runtime. This was touched a while back in #29102.

    Supporting retryStrategy: isolated via test.describe.configure() offers a granular control that doesn't break test distribution across shards. I can add a conditional if (testInfo.retry < 1) throw new Error('Run this test in isolation) at the top of test logic which prevents wasted runtime.

    Note: Our CI shards each spin up their own docker instance of our app, so cross-shard concurrency is a non-issue. Could be problematic otherwise.

  6. alok-108 commented on Oct 14, 2026

    @alok-108
  7. yury-s commented on Oct 15, 2026

    @yury-s
    Member

    Hi, the Playwright bot looked into this on my behalf.

    The sharding objection is right. Dependency projects are taken out before the shard filter and added back whole (runner/loadUtils.ts), so every shard that gets an exclusive test runs all of main first. The separate-project setup doesn't carry over to sharded CI, which leaves this request standing. The runtime side is small; what needs a decision first is the shape of the API.

    What the runner does today, as far as it bears on the design:

    • retryStrategy: 'isolated' already works per shard: each shard holds back its retries until its own workers are idle and never coordinates with other shards. A per-suite option would behave the same way, which fits a setup where every shard has its own app instance.
    • The dispatcher sorts failed tests into an immediate job or an isolated job in one place (JobDispatcher in runner/dispatcher.ts); reading the test's strategy there instead of config.retryStrategy is the whole runtime change. The scheduler already starts an isolated job only when every worker is idle and always picks queued regular jobs first, so immediate and isolated retries can coexist in one run without touching it.

    Open questions before a PR:

    1. Scope. retries can be set in the config, per project and in test.describe.configure(). Should retryStrategy follow it to all three? A project-level option on its own already covers this case without project dependencies, and it shards fine:
      { name: 'exclusive', testMatch: /exclusive/, retryStrategy: 'isolated' }
    2. Serial suites. All tests of a failed serial suite are retried together as one job. A retryStrategy set on a suite nested inside a serial suite would split that job in two. The option would have to come from the serial root, or be rejected inside a serial suite the way a conflicting mode is today.

    Investigated locally by the Playwright bot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions