Skip to content

Commit 6e823e2

Browse files
jtligonclaude
andcommitted
test: fix flaky test_drain_exits_when_deadline_exceeded_before_select
The test was racing - the clock manipulation would either exit too early (before reading "DEADLINE_TEST") or too late (after reading "SHOULD_NOT_APPEAR"). Fixed by making timing deterministic: track when the main output has been flushed, then trigger timeout only after that point but before reading "SHOULD_NOT_APPEAR". This fixes intermittent failures where the assertion would fail because the drain exited at the wrong time. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent dad0ecd commit 6e823e2

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

python/packages/jumpstarter/jumpstarter/exporter/hooks_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, *, return_drain_data: bool = True) -> None:
3232
self.parent_fd: int | None = None
3333
self.eof_seen: bool = False
3434
self._drain_data_returned: bool = False
35+
self._main_output_flushed: bool = False
3536
self._return_drain_data = return_drain_data
3637
self._original_openpty = pty.openpty
3738
self._original_os_read = os.read
@@ -52,8 +53,12 @@ def os_read_with_drain_data(self, fd, size):
5253
raise
5354
if not data:
5455
self.eof_seen = True
56+
self._main_output_flushed = True
5557
return b""
5658
return data
59+
# After EOF, first empty read means main output was flushed
60+
if not self._main_output_flushed:
61+
self._main_output_flushed = True
5762
if self._return_drain_data and not self._drain_data_returned:
5863
self._drain_data_returned = True
5964
return b"SHOULD_NOT_APPEAR\n"
@@ -83,7 +88,9 @@ def __call__(self) -> float:
8388
if self._call_count == 1:
8489
self._deadline = real_time + DRAIN_TIMEOUT_SECONDS
8590
return real_time
86-
if self._call_count == 2:
91+
# Stay just before deadline until "DEADLINE_TEST" is read,
92+
# then jump past deadline to force early exit before "SHOULD_NOT_APPEAR"
93+
if not getattr(self._state, '_main_output_flushed', False):
8794
return self._deadline - 0.001 # type: ignore[operator]
8895
return self._deadline + 1.0 # type: ignore[operator]
8996

0 commit comments

Comments
 (0)