Skip to content

Commit 5f2b169

Browse files
authored
test: let the restarted silent-stream log end before stopping it (#1112)
`test_streamed_log_sync_stop_returns_on_silent_stream` restarts the log and calls `stop()` right away. When `stop()` lands before the restarted stream delivers its line, the thread falls back to reading the whole log, which the test doesn't serve. The 500 then goes through the client's retry backoff for longer than the 5 s `join`, and the final `Log redirection stopped due to unexpected error` record shows up in the `caplog` of a later test on the same xdist worker ([failed run](https://github.com/apify/apify-client-python/actions/runs/37913292009/job/113763322520)). The test now waits for the restarted thread to finish on its own (the released server ends the stream after one line), asserts that it did, and only then calls `stop()`. Running the two tests back to back failed 12/12 before the change and passes after it. *✍️ Drafted by Claude Code*
1 parent a370e7a commit 5f2b169

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎tests/unit/test_logging.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,11 @@ def generate_logs() -> Iterator[bytes]:
12701270
assert not streaming_thread.is_alive()
12711271
restarted_thread = streamed_log.start()
12721272
assert restarted_thread is not streaming_thread
1273-
streamed_log.stop()
1273+
# The released server ends the stream after its line, so the thread finishes on its own. A `stop` before that
1274+
# line arrived would read the whole log, which this test does not serve.
12741275
restarted_thread.join(timeout=5)
1276+
assert not restarted_thread.is_alive()
1277+
streamed_log.stop()
12751278

12761279

12771280
@pytest.mark.usefixtures('propagate_stream_logs')

0 commit comments

Comments
 (0)