Skip to content

fix(test): bootstrap-k8s test waits 45 s for the Docker poll #4466

Closed

Description

@dan-petty

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

  1. Run uv run pytest "tests/commands/test_devcontainer.py::TestDevcontainerCli::test_bootstrap_k8s_warns_when_docker_daemon_down" -n0 --durations=3.
  2. 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 the clock fixture
  • THEN the function returns False and clock.waits holds 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-k8s with the Docker engine fake unreachable
  • THEN the command exits 0, the output contains Docker daemon is not running, and clock.waits records 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_daemon read time and wait?: Import the devops_cli.core.clock module and call clock.monotonic() and clock.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 ClockFake controls these calls, and the testing rule requires the clock fixture for waits.
    • Rejected: Keep time.monotonic() and time.sleep(). These calls bypass ClockFake and make the test wait 45 seconds in real time.
    • Rejected: Patch time.sleep in the test. A patch hides the production call, and the project already routes waits through clock.
  • How should the slow bootstrap-k8s test check the poll without real time?: Ask for the clock fixture and assert that clock.waits holds 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. ClockFake records 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.
  • 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.waits holds 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

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: none. The title has the scope test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.
    • Priority: P2-Medium. A 45 s test holds one CI worker per run but does not break functionality.
    • Value: Medium. Saves 45 s per run and frees a CI shard, but the project still passes without this fix.
    • Effort: Low. Replace two time calls with clock calls and add the clock fixture to one test.
    • Related: refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320, which asks for a different change. 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.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 54743c4 (see proposed design in issue body).

  6. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the CI audit (2026-11-11)

    Another session works on this issue now. This comment only adds the measured cause.

    • The test is a CPU busy-spin, not a wait. The test fakes time.sleep, but time.monotonic is real. So _wait_for_docker_daemon (src/devops_cli/commands/devcontainer.py:911-920) calls ping() 59,918 times in 45 s, with 37.5 s of CPU (measured). The test takes 45.01 s in CI.
    • Solution: route the loop through devops_cli.core.clock for both sleep and monotonic, so that the shared ClockFake answers both.
    • Acceptance: the test takes 1 s or less, with 0 real sleeps and 2 s of CPU or less.
    • Saving: 45 s of wall time and 37 s of CPU per run (measured).
    • fix(tests): refuse real sleeps in tests #4669 (refuse real sleeps in tests) waits for this issue.
  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 11, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 11, 2026
  9. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 19:36 UTC

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

    effort/lowpriority/p2-mediumsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions