Repository navigation
Description
Problem or Motivation
tests/test_telemetry_shutdown_sync.py::test_shutdown_joins_all_worker_threads failed once in a full uv run devops ci run with 16 workers on a loaded host. The run was on the branch of #2665, which does not touch telemetry. The test passes alone and passed in the run before.
The failure: after client.shutdown(), two devops-otel threads were still alive. The test waits for a thread with fixed timers (a threading.Timer(1.2, ...), started.wait(timeout=1.0) and finish.wait(timeout=3.0)). A loaded host stretches these times, and docs/TESTING.md says a test must not depend on them.
Proposed Solution & Architectural Design
Make the test wait for the events it needs, with THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py, and not with its own timers.
Target Subsystem
tests/test_telemetry_shutdown_sync.py, src/devops_cli/telemetry/.
Existing Tool Considered
tests/support/waits.py (wait_until, THREAD_HANDOFF_BOUND_SECONDS).
Acceptance criteria
- The test passes in a full
uv run devops cirun on a loaded host.
Proposed design
Problem statement
The test test_shutdown_joins_all_worker_threads uses fixed timers (1.0 s, 1.2 s, 3.0 s) to coordinate with worker threads. On a loaded host these timers expire before the threads finish, so the test fails. The test must wait for the events it needs using THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py, and must not use its own fixed timers.
Acceptance criteria
Requirement: Waits use the shared bound
The test SHALL use THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py for every wait on a thread event, and SHALL NOT use a threading.Timer with a fixed delay or an Event.wait with a timeout below that bound.
Scenario: No fixed timer in test source
- WHEN The test file tests/test_telemetry_shutdown_sync.py is read
- THEN No threading.Timer with a fixed delay and no Event.wait with a timeout below THREAD_HANDOFF_BOUND_SECONDS appears in the test
Requirement: Shutdown blocks on in-flight send
The test SHALL verify that client.shutdown() does not return until the in-flight executor thread has completed its send.
Scenario: Shutdown waits for in-flight send
- WHEN A send is in-flight and blocked on the finish event, and shutdown is called
- THEN shutdown returns only after the send completes, and client._executor is None
Requirement: No otel threads remain after shutdown
After client.shutdown() returns, the test SHALL assert that no thread whose name starts with devops-otel is alive.
Scenario: All otel threads joined
- WHEN shutdown has returned and the in-flight send has completed
- THEN threading.enumerate() contains no alive thread whose name starts with devops-otel
Existing Tool Considered
No external tool is needed. The project already has tests/support/waits.py, which provides THREAD_HANDOFF_BOUND_SECONDS (30.0 s) and wait_until. No check has run. The change uses this existing module and adds no new dependency.
Key questions
- How should the test release the in-flight send without a fixed timer?: Run client.shutdown() in a daemon thread, set the finish event from the main thread, and wait for the shutdown thread with THREAD_HANDOFF_BOUND_SECONDS. (best practice) [sources: docs/TESTING.md:137, tests/support/waits.py:33]
- Rejected: threading.Timer with a fixed delay. A fixed delay is a deadline of its own, which TESTING.md forbids for thread waits.
- Rejected: Run shutdown in a thread, release from main, wait with the bound. No fixed timer. The wait returns as soon as the event fires, so a passing test is not slowed.
- Rejected: Call finish.set() before shutdown(). The send may complete before shutdown is called, so the test no longer verifies that shutdown blocks on an in-flight send.
- What bound should the waits use?: THREAD_HANDOFF_BOUND_SECONDS (30.0 seconds) from tests/support/waits.py. [sources: tests/support/waits.py:33, docs/TESTING.md:137]
- Should the test keep monkeypatch.setattr for _send_payload_sync?: Yes. The issue scope is the timers. Changing the patch mechanism is a separate concern tracked by the TESTING.md migration. (best practice) [sources: tests/test_telemetry_shutdown_sync.py, docs/TESTING.md]
- Rejected: Keep monkeypatch.setattr for _send_payload_sync. The issue scope is the timers. The existing patch is the current approach.
- Rejected: Use a seam or fake for the send. Out of scope. The TESTING.md migration to seams is tracked separately.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 29, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The change fixes a flaky test by replacing timers with event-based waits.A flaky CI test breaks builds on loaded hosts but does not affect production users.Reliable CI is needed for the team, but the change does not alter user-facing behaviour.One test file changes its wait strategy using an existing helper in tests/support/waits.py.Replace fixed timers in test_shutdown_joins_all_worker_threads with event-based waits using THREAD_HANDOFF_BOUND_SECONDSas the change that both ask for.Both items fix the same test in the same file by replacing wall-clock timers with event-based waits.A person closes one of the two if that is so.devops-cli-service commentedon Oct 30, 2026
Status set to Ready at 46fd02d (see proposed design in issue body).
chore(main): release 0.36.0 (#2943)