Skip to content

Commit 7c0634b

Browse files
rustyconoverclaude
andcommitted
test_stop_force: sleep 2 s per row and hold the kill to half of it
test_force_returns_promptly_mid_stream spent 5 s waiting for the first row, because the fixture sleeps before each row. Its bound was the sleep itself, which a stop that waited out the current sleep would still meet by a few milliseconds. The sleep is now 2 s and the forced stop must take under half of it: a kill takes milliseconds, and a stop that waited for the sleep now fails. The test takes 3 s less. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6cc522a commit 7c0634b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎tests/client/test_stop_force.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
from vgi.arguments import Arguments
2727
from vgi.client.client import Client, _default_pool
2828

29-
# Long enough that a graceful teardown would have to wait on it if the worker were stuck.
30-
_SLEEP_MS = 5_000
29+
# How long the worker sleeps before each row. The first row alone costs this
30+
# much, so it is kept short; the forced stop is held to half of it (see
31+
# test_force_returns_promptly_mid_stream), which a teardown that waited out the
32+
# sleep would miss by a wide margin, and a kill (milliseconds) clears.
33+
_SLEEP_MS = 2_000
3134

3235

3336
def _started_client(**kwargs: Any) -> Client:
@@ -65,10 +68,13 @@ def test_force_returns_promptly_mid_stream(tmp_path: Any) -> None:
6568
)
6669
next(gen) # worker is now mid-stream, sleeping between batches
6770

71+
# The client's reader thread asks for the next row as soon as it has the
72+
# first, so the worker is now inside that row's sleep. A stop that waited
73+
# it out would take nearly the whole sleep; hold the kill to half of it.
6874
started = time.monotonic()
6975
client.stop(force=True)
7076
elapsed = time.monotonic() - started
71-
assert elapsed < _SLEEP_MS / 1000.0, f"forced stop waited {elapsed:.2f}s on a sleeping worker"
77+
assert elapsed < _SLEEP_MS / 2000.0, f"forced stop waited {elapsed:.2f}s on a sleeping worker"
7278

7379

7480
def test_graceful_stop_is_unchanged() -> None:

0 commit comments

Comments
 (0)