Repository navigation
Description
Problem Description
tests/commands/test_devcontainer.py::TestDevcontainerCli::test_bootstrap_k8s_warns_when_docker_daemon_down takes 45 s on every run: 45.01 s on a GitHub runner (shard 4 of run 42938256840 on main, 2026-11-11), and 46.1 s in each of 12 local gate logs under load.
The cause: _wait_for_docker_daemon in src/devops_cli/commands/devcontainer.py polls with time.monotonic() and time.sleep(2) up to its default of 45 s. The test makes the Docker engine fake unreachable, so the loop runs to its end. The function does not use the clock seam devops_cli.core.clock (sleep, monotonic), so the shared clock fixture (ClockFake) cannot answer the waits.
Reproduction Steps
- Run
uv run pytest "tests/commands/test_devcontainer.py::TestDevcontainerCli::test_bootstrap_k8s_warns_when_docker_daemon_down" -n0 --durations=3. - Read the time: about 45 s.
Expected vs Actual Behavior
Expected: the test takes well under 1 s.
Actual: 45 s, one CI worker held for the whole time.
Proposed fix
Make _wait_for_docker_daemon wait through the clock seam (clock.monotonic() and clock.sleep()), as other polling loops of the project do. Then the test asks for the clock fixture and asserts the polls it recorded in clock.waits (waits of 2 s until 45 s pass).
Environment Diagnostics
GitHub-hosted ubuntu-26.04 runners and the devcontainer on WSL2.
Logs, Traces, or Terminal Output
Found by the measurement of #4405.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Proposed design
Problem statement
The bootstrap-k8s warning test waits 45 seconds on every run. _wait_for_docker_daemon uses time.monotonic() and time.sleep() directly, so the ClockFake cannot answer its waits. The change routes the poll through the clock seam and makes the test assert the recorded waits.
Acceptance criteria
Requirement: Docker daemon poll uses the clock seam
_wait_for_docker_daemon SHALL measure elapsed time with clock.monotonic() and wait with clock.sleep() from devops_cli.core.clock.
Scenario: Unreachable Docker engine
- WHEN the Docker engine fake is unreachable and
_wait_for_docker_daemon(timeout_seconds=45)runs with theclockfixture - THEN the function returns False and
clock.waitsholds 23 waits of 2 seconds.
Requirement: Bootstrap-k8s warning test uses the fake clock
The test_bootstrap_k8s_warns_when_docker_daemon_down test SHALL ask for the clock fixture and assert the waits that the poll records.
Scenario: Docker daemon down during bootstrap
- WHEN the test runs
bootstrap-k8swith the Docker engine fake unreachable - THEN the command exits 0, the output contains
Docker daemon is not running, andclock.waitsrecords the poll waits without real time passing.
Requirement: Poll keeps the production timeout
_wait_for_docker_daemon MUST keep the default timeout of 45 seconds.
Scenario: Default timeout
- WHEN a caller invokes
_wait_for_docker_daemon()with no timeout argument and the engine stays unreachable - THEN the function polls until 45 seconds pass on the clock and returns False.
Existing Tool Considered
No alternatives check has run. No open, maintained external tool covers this repository-specific test fix. The existing devops_cli.core.clock seam and ClockFake cover the need, so the change builds no new code to keep.
Key questions
- How should
_wait_for_docker_daemonread time and wait?: Import thedevops_cli.core.clockmodule and callclock.monotonic()andclock.sleep()at each poll. (best practice) [sources: src/devops_cli/commands/devcontainer.py:911, src/devops_cli/core/clock.py, tests/support/fakes/clock.py, .ast-grep/rules/test-elapsed-upper-bound.yml]- Chosen: Use the clock seam. The
ClockFakecontrols these calls, and the testing rule requires the clock fixture for waits. - Rejected: Keep
time.monotonic()andtime.sleep(). These calls bypassClockFakeand make the test wait 45 seconds in real time. - Rejected: Patch
time.sleepin the test. A patch hides the production call, and the project already routes waits throughclock.
- Chosen: Use the clock seam. The
- How should the slow bootstrap-k8s test check the poll without real time?: Ask for the
clockfixture and assert thatclock.waitsholds the 2-second waits. (best practice) [sources: tests/commands/test_devcontainer.py:356, tests/support/fakes/clock.py, .ast-grep/rules/test-elapsed-upper-bound.yml, .ast-grep/rule-tests/test-elapsed-upper-bound-test.yml]- Chosen: Assert
clock.waits.ClockFakerecords each wait, and the rule forbids an upper bound on elapsed wall time. - Rejected: Assert elapsed wall time is under 1 second. A loaded runner makes wall time longer, and the rule forbids this assertion.
- Rejected: Keep the test unchanged. The test still waits 45 seconds and holds a CI worker.
- Chosen: Assert
- Should the default 45-second timeout change?: No. Keep the 45-second default, because the change only replaces the clock source. (best practice) [sources: src/devops_cli/commands/devcontainer.py:911, src/devops_cli/commands/devcontainer.py:944]
- Chosen: Keep 45 seconds. The production behavior stays the same, and the issue reports only the test time.
- Rejected: Reduce the timeout. This changes production behavior and can skip a slow Docker daemon start.
- How many waits does the default poll record with the fake clock?: With a 45-second timeout and a 2-second sleep,
clock.waitsholds 23 waits of 2 seconds. [sources: src/devops_cli/commands/devcontainer.py:911]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.A 45 s test holds one CI worker per run but does not break functionality.Saves 45 s per run and frees a CI shard, but the project still passes without this fix.Replace two time calls with clock calls and add the clock fixture to one test.Both make source code use the clock seam so tests avoid real-time waits, but #1320 is the broad umbrella and this targets one remaining function in devcontainer.py.devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 54743c4 (see proposed design in issue body).
dan-petty commentedon Nov 11, 2026
Scope from the CI audit (2026-11-11)
Another session works on this issue now. This comment only adds the measured cause.
time.sleep, buttime.monotonicis real. So_wait_for_docker_daemon(src/devops_cli/commands/devcontainer.py:911-920) callsping()59,918 times in 45 s, with 37.5 s of CPU (measured). The test takes 45.01 s in CI.devops_cli.core.clockfor bothsleepandmonotonic, so that the sharedClockFakeanswers both.devops-cli-service commentedon Nov 11, 2026
Released in v0.112.3: https://github.com/dan-petty/devops-cli/releases/tag/v0.112.3
devops-cli-service commentedon Nov 11, 2026
Live since 2026-11-11 19:36 UTC