Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tst/unit/env/gateway/triggers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,19 +1492,20 @@ async def fake_sleep(self, until, generation=None):


class _SteppedClock:
"""The engine's clock on a fake source that asyncio.sleep advances, so the real virtual-time waits run at once;
`.at[n]` runs after the n-th sleep."""
"""The engine's clock on a fake source that the engine's own naps advance, so the real virtual-time waits run at
once; `.at[n]` runs after the n-th nap. Only this engine's naps count: the tests share one event loop, where
waits other tests left running still sleep."""

def __init__(self, engine, monkeypatch):
self.t = 0.0
self.slept: list[float] = []
self.at: dict = {}
self.clock = engine._test_gw._clock = Clock(now_fn=lambda: self.t)

async def fake_sleep(seconds):
async def fake_nap(seconds):
self.slept.append(seconds)
assert len(self.slept) < 100, "the wait never ended"
self.t += seconds
self.at.pop(len(self.slept), lambda: None)()

monkeypatch.setattr(triggers_module.asyncio, "sleep", fake_sleep)
monkeypatch.setattr(engine, "_nap", fake_nap)
Loading