Skip to content

Commit 833ab82

Browse files
AugustoSandimclaude
andcommitted
test(source-chat): advance the fake clock monotonically in the keepalive test
The previous counter froze the clock at 100.0 for every call after the first, which left the due-keepalive check at 0 forever if the generation loop ever iterated twice. A monotonically increasing clock keeps the keepalive-before-final-response regression test meaningful under any number of polls. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c213853 commit 833ab82

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

tests/test_chat_routers_characterization.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,15 @@ async def test_stream_source_chat_emits_due_keepalive_before_final_response():
711711
from api.routers import source_chat as source_chat_router
712712
from api.routers.source_chat import stream_source_chat_response
713713

714-
# The fake clock puts the (instant) completion far past the keepalive
715-
# interval: initialization reads 0, the completion poll reads 100.
716-
counter = 0
714+
# The fake clock advances 100s per call: the initialization read is 0 and
715+
# the completion poll is 100, so a due keepalive must precede the final
716+
# response (the done-branch runs only after the keepalive check).
717+
ticks = 0
717718
def fake_monotonic():
718-
nonlocal counter
719-
counter += 1
720-
return 100.0 if counter > 1 else 0.0
719+
nonlocal ticks
720+
value = ticks * 100.0
721+
ticks += 1
722+
return value
721723
fake_time = SimpleNamespace(monotonic=fake_monotonic)
722724

723725
with patch.object(

0 commit comments

Comments
 (0)