Skip to content

Run parallel workers in throwaway Docker containers - #408

Draft
schlessera wants to merge 5 commits into
perf/parallel-scenariosfrom
perf/docker-workers
Draft

schlessera wants to merge 5 commits into
perf/parallel-scenariosfrom
perf/docker-workers

Conversation

@schlessera

@schlessera schlessera commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Addresses the first two steps of #391. Builds on #405.

With WP_CLI_TEST_DOCKER set, the scenarios run in throwaway containers, every parallel worker in its own, next to its own database server container. This makes the workers fully independent:

  • Each has its own network, temporary directory and database server, so any worker can run any scenario, including the ones using fixed ports or fixed temporary paths, which otherwise all have to run in the first worker.
  • The database servers are of the same type and version as the configured one, unless WP_CLI_TEST_DOCKER_DB names an image, and keep their data in memory.
  • The containers check PHP extensions, PHP versions and the database themselves.
  • WordPress is downloaded once on the host and shared read-only with the containers.
  • Scenarios selected by path or name run in a single container.

Docker stays optional:

WP_CLI_TEST_DOCKER Effect
not set (default), 0, no, off The scenarios run without Docker.
auto The scenarios run in containers where possible, and without Docker otherwise, which is reported.
1, yes, on The scenarios run in containers, and the run fails where that is not possible.

Docker cannot be used on Windows, when collecting code coverage, when it is not available, when the image cannot be built or when the database server cannot be identified.

The containers run the host's PHP version, unless WP_CLI_TEST_DOCKER_PHP sets another one, e.g. 7.4. The project's Composer dependencies are then installed for that version in a separate directory (about 3 seconds with a warm Composer cache), and refreshed once a day. Dependencies linked to local checkouts, as in wp-cli/wp-cli-dev, come from their published versions in that case, which is reported. The image falls back to the Debian archive for PHP versions whose base images are on archived Debian releases.

Locally, the 97 scenarios of this package take 68 seconds serially, 35 seconds with 4 parallel workers, 41 seconds with 4 workers in containers on the host's PHP 8.5, and 30 seconds in containers on PHP 7.4. cache-command ran the same 24 scenarios and 478 steps as a serial run with 4 workers, in 59 seconds including about 8 seconds for starting the containers and database servers. The third step of #391, restoring the cached installation as a copy-on-write snapshot, needs elevated privileges in the containers and is left for later.

This also stops options that take a value, as in --format progress, from being taken for paths, which made the scenarios run one after the other.

Measurements on CI are recorded on #391.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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 github-actions Bot added the scope:testing Related to testing label Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

schlessera and others added 2 commits October 31, 2026 14:37
With WP_CLI_TEST_DOCKER set and Docker available, every worker runs in
its own container, next to its own database server container of the same
type and version as the configured one. Workers share no network, temporary
directory or database, so any of them can run any scenario, including the
ones using fixed ports or fixed temporary paths. The database servers keep
their data in memory.

The containers run the same PHP version as the host, which the project's
Composer dependencies are installed for, and use WordPress as downloaded
once by the host. Where the image cannot be built or the database server
cannot be identified, the scenarios run without Docker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test outcomes depend on how PHP reports errors. Without a php.ini, the
containers reported E_ALL, which WP-CLI keeps while testing, whereas the
CI runners report -1, which WP-CLI reduces to everything but deprecations.
Scenarios running older WordPress versions on PHP 8 therefore failed in
the containers on deprecation notices that the runners never print.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
schlessera and others added 3 commits October 31, 2026 18:29
Background processes such as the built-in web server are stopped through ps,
without which they keep their port for the next scenario.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… PHP version

WP_CLI_TEST_DOCKER=auto runs the scenarios without Docker where it cannot be
used, and reports why. 1 fails instead. Scenarios selected by path or name run
in a single container. WP_CLI_TEST_DOCKER_PHP runs the containers on another
PHP version than the host's, with the Composer dependencies installed for it.

Options taking a value, as in --format progress, are no longer mistaken for paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant