23
23
_MOCKED_ACTOR_LOGS = (
24
24
b'2025-05-13T07:24:12.588Z ACTOR: Pulling Docker image of build.\n '
25
25
b'2025-05-13T07:24:12.686Z ACTOR: Creating Docker container.\n '
26
- b'2025-05-13T07:24:12.745Z ACTOR: Starting Docker container.' , # Several logs merged into one message
26
+ b'2025-05-13T07:24:12.745Z ACTOR: Starting Docker container.' , # Several logs merged into one chunk
27
+ b'2025-05-13T07:26:14.132Z [apify] DEBUG \xc3 ' , # Chunked log split in the middle of the multibyte character
28
+ b'\xa1 ' , # part 2
27
29
b'2025-05-13T07:24:14.132Z [apify] INFO multiline \n log' ,
28
30
b'2025-05-13T07:25:14.132Z [apify] WARNING some warning' ,
29
31
b'2025-05-13T07:26:14.132Z [apify] DEBUG c' ,
30
- b'2025-05-13T0' , # Chunked log that got split in the marker, part 1
31
- b'7:26:14.132Z [apify] DEBUG d' # Chunked log that got split in the marker, part 2
32
- b'2025-05-13T07:26:14.132Z [apify] DEB' , # Chunked log that got split outside of marker, part 1
33
- b'UG e' , # Chunked log that got split outside of marker, part 1
32
+ b'2025-05-13T0' , # Chunked log that got split in the marker
33
+ b'7:26:14.132Z [apify] DEBUG d' # part 2
34
+ b'2025-05-13T07:26:14.132Z [apify] DEB' , # Chunked log that got split outside of marker
35
+ b'UG e' , # part 2
34
36
)
35
37
36
38
_EXPECTED_MESSAGES_AND_LEVELS = (
37
39
('2025-05-13T07:24:12.588Z ACTOR: Pulling Docker image of build.' , logging .INFO ),
38
40
('2025-05-13T07:24:12.686Z ACTOR: Creating Docker container.' , logging .INFO ),
39
41
('2025-05-13T07:24:12.745Z ACTOR: Starting Docker container.' , logging .INFO ),
42
+ ('2025-05-13T07:26:14.132Z [apify] DEBUG á' , logging .DEBUG ),
40
43
('2025-05-13T07:24:14.132Z [apify] INFO multiline \n log' , logging .INFO ),
41
44
('2025-05-13T07:25:14.132Z [apify] WARNING some warning' , logging .WARNING ),
42
45
('2025-05-13T07:26:14.132Z [apify] DEBUG c' , logging .DEBUG ),
@@ -115,7 +118,9 @@ def propagate_stream_logs() -> None:
115
118
logging .getLogger (f'apify.{ _MOCKED_ACTOR_NAME } -{ _MOCKED_RUN_ID } ' ).setLevel (logging .DEBUG )
116
119
117
120
118
- @pytest .mark .parametrize (('log_from_start' , 'expected_log_count' ), [(True , 8 ), (False , 5 )])
121
+ @pytest .mark .parametrize (
122
+ ('log_from_start' , 'expected_log_count' ), [(True , len (_EXPECTED_MESSAGES_AND_LEVELS )), (False , 6 )]
123
+ )
119
124
@respx .mock
120
125
async def test_redirected_logs_async (
121
126
* ,
@@ -148,7 +153,9 @@ async def test_redirected_logs_async(
148
153
assert expected_message_and_level [1 ] == record .levelno
149
154
150
155
151
- @pytest .mark .parametrize (('log_from_start' , 'expected_log_count' ), [(True , 8 ), (False , 5 )])
156
+ @pytest .mark .parametrize (
157
+ ('log_from_start' , 'expected_log_count' ), [(True , len (_EXPECTED_MESSAGES_AND_LEVELS )), (False , 6 )]
158
+ )
152
159
@respx .mock
153
160
def test_redirected_logs_sync (
154
161
* ,
@@ -201,7 +208,7 @@ async def test_actor_call_redirect_logs_to_default_logger_async(
201
208
assert isinstance (logger .handlers [0 ], logging .StreamHandler )
202
209
203
210
# Ensure logs are propagated
204
- assert len (caplog .records ) == 8
211
+ assert len (caplog .records ) == len ( _EXPECTED_MESSAGES_AND_LEVELS )
205
212
for expected_message_and_level , record in zip (_EXPECTED_MESSAGES_AND_LEVELS , caplog .records ):
206
213
assert expected_message_and_level [0 ] == record .message
207
214
assert expected_message_and_level [1 ] == record .levelno
@@ -228,7 +235,7 @@ def test_actor_call_redirect_logs_to_default_logger_sync(
228
235
assert isinstance (logger .handlers [0 ], logging .StreamHandler )
229
236
230
237
# Ensure logs are propagated
231
- assert len (caplog .records ) == 8
238
+ assert len (caplog .records ) == len ( _EXPECTED_MESSAGES_AND_LEVELS )
232
239
for expected_message_and_level , record in zip (_EXPECTED_MESSAGES_AND_LEVELS , caplog .records ):
233
240
assert expected_message_and_level [0 ] == record .message
234
241
assert expected_message_and_level [1 ] == record .levelno
@@ -278,7 +285,7 @@ async def test_actor_call_redirect_logs_to_custom_logger_async(
278
285
with caplog .at_level (logging .DEBUG , logger = logger_name ):
279
286
await run_client .call (logger = logger )
280
287
281
- assert len (caplog .records ) == 8
288
+ assert len (caplog .records ) == len ( _EXPECTED_MESSAGES_AND_LEVELS )
282
289
for expected_message_and_level , record in zip (_EXPECTED_MESSAGES_AND_LEVELS , caplog .records ):
283
290
assert expected_message_and_level [0 ] == record .message
284
291
assert expected_message_and_level [1 ] == record .levelno
@@ -298,7 +305,7 @@ def test_actor_call_redirect_logs_to_custom_logger_sync(
298
305
with caplog .at_level (logging .DEBUG , logger = logger_name ):
299
306
run_client .call (logger = logger )
300
307
301
- assert len (caplog .records ) == 8
308
+ assert len (caplog .records ) == len ( _EXPECTED_MESSAGES_AND_LEVELS )
302
309
for expected_message_and_level , record in zip (_EXPECTED_MESSAGES_AND_LEVELS , caplog .records ):
303
310
assert expected_message_and_level [0 ] == record .message
304
311
assert expected_message_and_level [1 ] == record .levelno
0 commit comments