Skip to content

Commit cf2f1de

Browse files
smackeseyDagster Devtools
authored andcommitted
daemon-test-suite: parallelize tox env with -n 4 --dist loadgroup (#23512)
## Cause The `daemon-test-suite` `py312` tox env runs ~527s on CI for 38 tests, all serial. `pytest-xdist` 3.6.1 is loaded transitively via `dagster[test]`, but the tox `commands = pytest -s -vv {posargs}` line has no `-n` flag, so xdist never gets used. The 3 tests in `monitoring_daemon_tests/test_monitoring.py` share a session-scoped `hostnames` fixture wrapping `docker_compose_cm` — the same anti-pattern that broke PR #23506 (4 xdist workers each tried to bring up the same compose stack; 3 failed). This needs handling specifically; the remaining 35 tests don't share a docker compose stack and parallelize freely. ## Fix - Change tox `commands =` to `pytest -s -vv -n 4 --dist loadgroup {posargs}`. - Mark the 3 monitoring tests with `@pytest.mark.xdist_group(name="monitoring_compose")` so loadgroup co-locates them on a single worker (one compose stack per group, never racing). `--dist loadgroup` (rather than `worksteal`) is the right scheduler when some tests *must* go to the same worker; pytest-xdist guarantees same-group tests share a worker. Worker count is fixed at 4 because `os.cpu_count()` inside K8s pod runners returns 1, defeating `-n auto`. ## Before / after CI baseline: ~527s pytest serial (38 tests). Estimated CI: ~3 minutes saved per run. The 3 monitoring tests stay on one worker (their docker compose runtime is the floor); the remaining 35 spread across the other three workers, so wall-clock goes from `serial(38)` to roughly `max(serial(3 monitoring), serial(35) / 3)`. **Observed (job wall-clock, including tox setup):** | Build | Branch | daemon-test-suite-3-12 | |---|---|---| | [155030](https://buildkite.com/dagster/internal/builds/155030) | master | 417s (6m 57s) | | [155046](https://buildkite.com/dagster/internal/builds/155046) | this PR | **237s (3m 57s)** | **−180s, 1.76× speedup.** Lands at the optimistic end of the predicted floor (`max(monitoring_compose ≈ 240s, test_memory ≈ 150s)`) — the `monitoring_compose` group is now the bottleneck as designed. Local validation skipped — daemon-test-suite needs docker compose plus many dagster packages installed, so CI is the first real signal. Verified the Python `pytest.mark.xdist_group` decoration parses, and `tox.ini` parses as INI. ## Same assertions No tests added, removed, skipped, marked `xfail`, or modified. The decorator only affects worker assignment; xdist scheduling is the only behavior change. ## Notes `pytest-xdist` is already in the resolved deps via `dagster[test]` — no lockfile change required. This PR explicitly avoids the trap that bit PR #23506: marking the docker-compose-bound tests with an `xdist_group` is the simple alternative to making the underlying fixture xdist-safe. PR #23507 takes the deeper-fix approach for the dagster-cloud-e2e suite where many more tests share the same compose stack. Internal-RevId: 9974bcec3953a3c567ff2c23db405100ea16e3ec
1 parent f459954 commit cf2f1de

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

integration_tests/test_suites/daemon-test-suite/monitoring_daemon_tests/test_monitoring.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def log_run_events(instance, run_id):
9595
print(str(log) + "\n") # noqa: T201
9696

9797

98+
@pytest.mark.xdist_group(name="monitoring_compose")
9899
def test_monitoring():
99100
# with setup_instance() as instance:
100101
with instance_for_test(
@@ -116,6 +117,7 @@ def test_monitoring():
116117
assert all_daemons_healthy(instance)
117118

118119

120+
@pytest.mark.xdist_group(name="monitoring_compose")
119121
def test_docker_monitoring(docker_postgres_instance, aws_env):
120122
docker_image = get_test_project_docker_image()
121123

@@ -194,6 +196,7 @@ def test_docker_monitoring(docker_postgres_instance, aws_env):
194196
assert instance.get_run_by_id(run.run_id).status == DagsterRunStatus.SUCCESS
195197

196198

199+
@pytest.mark.xdist_group(name="monitoring_compose")
197200
def test_docker_monitoring_run_out_of_attempts(docker_postgres_instance, aws_env):
198201
docker_image = get_test_project_docker_image()
199202

integration_tests/test_suites/daemon-test-suite/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ allowlist_externals =
2828
uv
2929
commands =
3030
!windows: /bin/bash -c '! uv pip list --exclude-editable | grep -e dagster'
31-
pytest -s -vv {posargs}
31+
pytest -s -vv -n 4 --dist loadgroup {posargs}

0 commit comments

Comments
 (0)