@@ -175,14 +175,17 @@ async def main_outer() -> None:
175
175
assert run_result_outer is not None
176
176
assert run_result_outer ['status' ] == 'SUCCEEDED'
177
177
178
- await inner_actor .last_run ().wait_for_finish ()
178
+ await inner_actor .last_run ().wait_for_finish (wait_secs = 300 )
179
179
180
180
inner_output_record = await inner_actor .last_run ().key_value_store ().get_record ('OUTPUT' )
181
181
assert inner_output_record is not None
182
182
assert inner_output_record ['value' ] == f'{ test_value } _XXX_{ test_value } '
183
183
184
184
185
- async def test_actor_calls_another_actor (make_actor : ActorFactory ) -> None :
185
+ async def test_actor_calls_another_actor (
186
+ apify_client_async : ApifyClientAsync ,
187
+ make_actor : ActorFactory ,
188
+ ) -> None :
186
189
async def main_inner () -> None :
187
190
async with Actor :
188
191
await asyncio .sleep (5 )
@@ -210,19 +213,26 @@ async def main_outer() -> None:
210
213
inner_actor_id = (await inner_actor .get () or {})['id' ]
211
214
test_value = crypto_random_object_id ()
212
215
213
- outer_run_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
216
+ outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
217
+ assert outer_call_result is not None
218
+
219
+ run_client_outer = apify_client_async .run (outer_call_result ['id' ])
220
+ run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 300 )
214
221
215
- assert outer_run_result is not None
216
- assert outer_run_result ['status' ] == 'SUCCEEDED'
222
+ assert run_result_outer is not None
223
+ assert run_result_outer ['status' ] == 'SUCCEEDED'
217
224
218
- await inner_actor .last_run ().wait_for_finish ()
225
+ await inner_actor .last_run ().wait_for_finish (wait_secs = 300 )
219
226
220
227
inner_output_record = await inner_actor .last_run ().key_value_store ().get_record ('OUTPUT' )
221
228
assert inner_output_record is not None
222
229
assert inner_output_record ['value' ] == f'{ test_value } _XXX_{ test_value } '
223
230
224
231
225
- async def test_actor_calls_task (make_actor : ActorFactory , apify_client_async : ApifyClientAsync ) -> None :
232
+ async def test_actor_calls_task (
233
+ apify_client_async : ApifyClientAsync ,
234
+ make_actor : ActorFactory ,
235
+ ) -> None :
226
236
async def main_inner () -> None :
227
237
async with Actor :
228
238
await asyncio .sleep (5 )
@@ -255,12 +265,16 @@ async def main_outer() -> None:
255
265
task_input = {'test_value' : test_value },
256
266
)
257
267
258
- outer_run_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_task_id' : task ['id' ]})
268
+ outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_task_id' : task ['id' ]})
269
+ assert outer_call_result is not None
270
+
271
+ run_client_outer = apify_client_async .run (outer_call_result ['id' ])
272
+ run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 300 )
259
273
260
- assert outer_run_result is not None
261
- assert outer_run_result ['status' ] == 'SUCCEEDED'
274
+ assert run_result_outer is not None
275
+ assert run_result_outer ['status' ] == 'SUCCEEDED'
262
276
263
- await inner_actor .last_run ().wait_for_finish ()
277
+ await inner_actor .last_run ().wait_for_finish (wait_secs = 300 )
264
278
265
279
inner_output_record = await inner_actor .last_run ().key_value_store ().get_record ('OUTPUT' )
266
280
assert inner_output_record is not None
@@ -269,7 +283,10 @@ async def main_outer() -> None:
269
283
await apify_client_async .task (task ['id' ]).delete ()
270
284
271
285
272
- async def test_actor_aborts_another_actor_run (make_actor : ActorFactory ) -> None :
286
+ async def test_actor_aborts_another_actor_run (
287
+ apify_client_async : ApifyClientAsync ,
288
+ make_actor : ActorFactory ,
289
+ ) -> None :
273
290
async def main_inner () -> None :
274
291
async with Actor :
275
292
await asyncio .sleep (180 )
@@ -290,12 +307,16 @@ async def main_outer() -> None:
290
307
291
308
inner_run_id = (await inner_actor .start ())['id' ]
292
309
293
- outer_run_result = await outer_actor .call (run_input = {'inner_run_id' : inner_run_id })
310
+ outer_call_result = await outer_actor .call (run_input = {'inner_run_id' : inner_run_id })
311
+ assert outer_call_result is not None
294
312
295
- assert outer_run_result is not None
296
- assert outer_run_result ['status' ] == 'SUCCEEDED'
313
+ run_client_outer = apify_client_async .run (outer_call_result ['id' ])
314
+ run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 300 )
315
+
316
+ assert run_result_outer is not None
317
+ assert run_result_outer ['status' ] == 'SUCCEEDED'
297
318
298
- await inner_actor .last_run ().wait_for_finish ()
319
+ await inner_actor .last_run ().wait_for_finish (wait_secs = 300 )
299
320
inner_actor_last_run = await inner_actor .last_run ().get ()
300
321
assert inner_actor_last_run is not None
301
322
assert inner_actor_last_run ['status' ] == 'ABORTED'
@@ -304,7 +325,10 @@ async def main_outer() -> None:
304
325
assert inner_output_record is None
305
326
306
327
307
- async def test_actor_metamorphs_into_another_actor (make_actor : ActorFactory ) -> None :
328
+ async def test_actor_metamorphs_into_another_actor (
329
+ apify_client_async : ApifyClientAsync ,
330
+ make_actor : ActorFactory ,
331
+ ) -> None :
308
332
async def main_inner () -> None :
309
333
import os
310
334
@@ -342,10 +366,14 @@ async def main_outer() -> None:
342
366
inner_actor_id = (await inner_actor .get () or {})['id' ]
343
367
test_value = crypto_random_object_id ()
344
368
345
- outer_run_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
369
+ outer_call_result = await outer_actor .call (run_input = {'test_value' : test_value , 'inner_actor_id' : inner_actor_id })
370
+ assert outer_call_result is not None
371
+
372
+ run_client_outer = apify_client_async .run (outer_call_result ['id' ])
373
+ run_result_outer = await run_client_outer .wait_for_finish (wait_secs = 300 )
346
374
347
- assert outer_run_result is not None
348
- assert outer_run_result ['status' ] == 'SUCCEEDED'
375
+ assert run_result_outer is not None
376
+ assert run_result_outer ['status' ] == 'SUCCEEDED'
349
377
350
378
outer_run_key_value_store = outer_actor .last_run ().key_value_store ()
351
379
@@ -359,7 +387,10 @@ async def main_outer() -> None:
359
387
assert await inner_actor .last_run ().get () is None
360
388
361
389
362
- async def test_actor_reboots_successfully (make_actor : ActorFactory ) -> None :
390
+ async def test_actor_reboots_successfully (
391
+ apify_client_async : ApifyClientAsync ,
392
+ make_actor : ActorFactory ,
393
+ ) -> None :
363
394
async def main () -> None :
364
395
async with Actor :
365
396
print ('Starting...' )
@@ -374,7 +405,12 @@ async def main() -> None:
374
405
print ('Finishing...' )
375
406
376
407
actor = await make_actor ('actor_rebooter' , main_func = main )
377
- run_result = await actor .call (run_input = {'counter_key' : 'reboot_counter' })
408
+
409
+ call_result = await actor .call (run_input = {'counter_key' : 'reboot_counter' })
410
+ assert call_result is not None
411
+
412
+ run_client = apify_client_async .run (call_result ['id' ])
413
+ run_result = await run_client .wait_for_finish (wait_secs = 300 )
378
414
379
415
assert run_result is not None
380
416
assert run_result ['status' ] == 'SUCCEEDED'
@@ -387,7 +423,10 @@ async def main() -> None:
387
423
assert reboot_counter ['value' ] == 2
388
424
389
425
390
- async def test_actor_adds_webhook_and_receives_event (make_actor : ActorFactory ) -> None :
426
+ async def test_actor_adds_webhook_and_receives_event (
427
+ apify_client_async : ApifyClientAsync ,
428
+ make_actor : ActorFactory ,
429
+ ) -> None :
391
430
async def main_server () -> None :
392
431
import os
393
432
from http .server import BaseHTTPRequestHandler , HTTPServer
@@ -408,9 +447,7 @@ def do_POST(self) -> None: # noqa: N802
408
447
nonlocal webhook_body
409
448
content_length = self .headers .get ('content-length' )
410
449
length = int (content_length ) if content_length else 0
411
-
412
450
webhook_body = self .rfile .read (length ).decode ('utf-8' )
413
-
414
451
self .send_response (200 )
415
452
self .end_headers ()
416
453
self .wfile .write (bytes ('Hello, world!' , encoding = 'utf-8' ))
@@ -445,26 +482,29 @@ async def main_client() -> None:
445
482
server_actor_run = await server_actor .start ()
446
483
server_actor_container_url = server_actor_run ['containerUrl' ]
447
484
448
- # Give the server actor some time to start running
449
485
server_actor_initialized = await server_actor .last_run ().key_value_store ().get_record ('INITIALIZED' )
450
486
while not server_actor_initialized :
451
487
server_actor_initialized = await server_actor .last_run ().key_value_store ().get_record ('INITIALIZED' )
452
488
await asyncio .sleep (1 )
453
489
454
- client_actor_run_result = await client_actor .call (
455
- run_input = {'server_actor_container_url' : server_actor_container_url }
456
- )
457
- assert client_actor_run_result is not None
458
- assert client_actor_run_result ['status' ] == 'SUCCEEDED'
490
+ ac_call_result = await client_actor .call (run_input = {'server_actor_container_url' : server_actor_container_url })
491
+ assert ac_call_result is not None
492
+
493
+ ac_run_client = apify_client_async .run (ac_call_result ['id' ])
494
+ ac_run_result = await ac_run_client .wait_for_finish (wait_secs = 300 )
495
+
496
+ assert ac_run_result is not None
497
+ assert ac_run_result ['status' ] == 'SUCCEEDED'
498
+
499
+ sa_run_result = await server_actor .last_run ().wait_for_finish (wait_secs = 300 )
459
500
460
- server_actor_run_result = await server_actor .last_run ().wait_for_finish ()
461
- assert server_actor_run_result is not None
462
- assert server_actor_run_result ['status' ] == 'SUCCEEDED'
501
+ assert sa_run_result is not None
502
+ assert sa_run_result ['status' ] == 'SUCCEEDED'
463
503
464
504
webhook_body_record = await server_actor .last_run ().key_value_store ().get_record ('WEBHOOK_BODY' )
465
505
assert webhook_body_record is not None
466
506
assert webhook_body_record ['value' ] != ''
467
507
parsed_webhook_body = json .loads (webhook_body_record ['value' ])
468
508
469
- assert parsed_webhook_body ['eventData' ]['actorId' ] == client_actor_run_result ['actId' ]
470
- assert parsed_webhook_body ['eventData' ]['actorRunId' ] == client_actor_run_result ['id' ]
509
+ assert parsed_webhook_body ['eventData' ]['actorId' ] == ac_run_result ['actId' ]
510
+ assert parsed_webhook_body ['eventData' ]['actorRunId' ] == ac_run_result ['id' ]
0 commit comments