Skip to content

test(gateway): a stepped trigger clock counts only its own engine's naps - #720

Merged
earakely-scale merged 1 commit into
mainfrom
edgararakelyan/stepped-clock-own-naps
Nov 16, 2026
Merged

earakely-scale merged 1 commit into
mainfrom
edgararakelyan/stepped-clock-own-naps

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Three tests in tst/unit/env/gateway/triggers_test.py failed on an unrelated PR (#718, unit (1/2)), each with one extra 5.0 nap:

  • test_waiting_virtual_time_follows_the_clock_rate[armed-at-60x]: [5.0, 5.0, 5.0, 5.0, 5.0] == [5.0, 5.0, 5.0, 5.0]
  • test_waiting_virtual_time_follows_the_clock_rate[unarmed]: [5.0, 5.0, 2.0, 5.0] == [5.0, 5.0, 2.0]
  • test_waiting_virtual_time_holds_while_frozen_and_follows_a_new_rate: [5.0, 5.0, 5.0, 5.0] == [5.0, 5.0, 5.0, 2.0]

The helper they use, _SteppedClock, patched asyncio.sleep for the whole process and counted every call. The unit tier runs on one event loop per worker (asyncio_default_test_loop_scope = "session"), so a sleep from a task another test left running was counted as a step of the wait under test. 5.0 s is the engine's recheck interval, _VIRTUAL_RECHECK_S.

What changes

_SteppedClock patches the engine's own _nap instead. All five tests that use it wait through _sleep_virtual, which sleeps only through _nap, so they step exactly as before, and sleeps from other tests' tasks no longer count. Test-only.

Testing

  • Reproduced locally with a throwaway test that leaves a sleeping task behind, run just before these tests in one process. On main, one test fails. With this change, all 10 selected tests pass.
  • tst/unit/env/gateway/triggers_test.py passes six runs in a row with -n 4.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

This test-only change appears safe to merge.

Summary

Makes _SteppedClock replace one engine’s _nap instead of replacing asyncio.sleep for the whole process.

  • Gateway trigger tests count only naps from the engine they are testing.

Reviews (1) · Last reviewed commit: "test(gateway): a stepped trigger clock c..." · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 16, 2026 20:21
@earakely-scale
earakely-scale merged commit 7858fe6 into main Nov 16, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/stepped-clock-own-naps branch November 16, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant