Skip to content

Commit bdc6769

Browse files
authored
test: serve the whole-log fallback in the streamed log mocks (#1114)
Fixes a flaky `test_actor_call_redirect_logs_to_default_logger_async[httpx2]` ([failed run](https://github.com/apify/apify-client-python/actions/runs/38167530123/attempts/1)). When `call()` finishes before the log stream delivers its first chunk, `StreamedLog` reads the whole log with `GET /log?raw=true` (added in #1084). The `mock_api` and `mock_api_failing_status_poll` fixtures didn't serve that endpoint. In `test_actor_call_returns_run_when_status_poll_fails_sync`, the sync thread then retried the 500 with backoff, outlived the 5 s join in `stop()`, and logged its error into the next test's `caplog` on the same xdist worker. Both fixtures now serve the whole log on that endpoint. Locally the failure went from 2/10 to 0/40 with the two tests in CI order, and `test_logging.py` under `-n auto` passed 30/30. *✍️ Drafted by Claude Code*
1 parent 5ab509e commit bdc6769

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎tests/unit/test_logging.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def mock_api(httpserver: HTTPServer) -> None:
227227
httpserver.expect_request(
228228
f'/v2/actor-runs/{_MOCKED_RUN_ID}/log', method='GET', query_string='stream=true&raw=true'
229229
).respond_with_handler(_streaming_log_handler)
230+
# A streamed log stopped before its first chunk falls back to reading the whole log.
231+
httpserver.expect_request(
232+
f'/v2/actor-runs/{_MOCKED_RUN_ID}/log', method='GET', query_string='raw=true'
233+
).respond_with_data(b''.join(_MOCKED_ACTOR_LOGS), content_type='application/octet-stream')
230234

231235

232236
@pytest.fixture
@@ -1137,6 +1141,9 @@ def _status_handler(request: Request) -> Response:
11371141
httpserver.expect_request(
11381142
f'/v2/actor-runs/{_MOCKED_RUN_ID}/log', method='GET', query_string='stream=true&raw=true'
11391143
).respond_with_handler(_streaming_log_handler)
1144+
httpserver.expect_request(
1145+
f'/v2/actor-runs/{_MOCKED_RUN_ID}/log', method='GET', query_string='raw=true'
1146+
).respond_with_data(b''.join(_MOCKED_ACTOR_LOGS), content_type='application/octet-stream')
11401147

11411148

11421149
@pytest.mark.usefixtures('mock_api_failing_status_poll', 'propagate_stream_logs')

0 commit comments

Comments
 (0)