12
12
from apify ._models import ActorRun
13
13
14
14
if TYPE_CHECKING :
15
+ from collections .abc import Iterable
16
+
15
17
from apify_client import ApifyClientAsync
16
18
from apify_client .clients import ActorClientAsync
17
19
@@ -63,20 +65,33 @@ async def ppe_actor(
63
65
return apify_client_async .actor (ppe_actor_build )
64
66
65
67
68
+ def retry_counter (retry_count : int ) -> Iterable [tuple [bool , int ]]:
69
+ for retry in range (retry_count - 1 ):
70
+ yield False , retry
71
+
72
+ yield True , retry_count - 1
73
+
74
+
66
75
async def test_actor_charge_basic (
67
76
ppe_actor : ActorClientAsync ,
68
77
run_actor : RunActorFunction ,
69
78
apify_client_async : ApifyClientAsync ,
70
79
) -> None :
71
80
run = await run_actor (ppe_actor )
72
81
73
- # Wait until the platform gets its act together and refetch
74
- await asyncio .sleep (6 )
75
- updated_run = await apify_client_async .run (run .id ).get ()
76
- run = ActorRun .model_validate (updated_run )
82
+ # Refetch until the platform gets its act together
83
+ for is_last_attempt , _ in retry_counter (30 ):
84
+ await asyncio .sleep (1 )
85
+ updated_run = await apify_client_async .run (run .id ).get ()
86
+ run = ActorRun .model_validate (updated_run )
77
87
78
- assert run .status == ActorJobStatus .SUCCEEDED
79
- assert run .charged_event_counts == {'foobar' : 4 }
88
+ try :
89
+ assert run .status == ActorJobStatus .SUCCEEDED
90
+ assert run .charged_event_counts == {'foobar' : 4 }
91
+ break
92
+ except AssertionError :
93
+ if is_last_attempt :
94
+ raise
80
95
81
96
82
97
async def test_actor_charge_limit (
@@ -86,10 +101,16 @@ async def test_actor_charge_limit(
86
101
) -> None :
87
102
run = await run_actor (ppe_actor , max_total_charge_usd = Decimal ('0.2' ))
88
103
89
- # Wait until the platform gets its act together and refetch
90
- await asyncio .sleep (6 )
91
- updated_run = await apify_client_async .run (run .id ).get ()
92
- run = ActorRun .model_validate (updated_run )
93
-
94
- assert run .status == ActorJobStatus .SUCCEEDED
95
- assert run .charged_event_counts == {'foobar' : 2 }
104
+ # Refetch until the platform gets its act together
105
+ for is_last_attempt , _ in retry_counter (30 ):
106
+ await asyncio .sleep (1 )
107
+ updated_run = await apify_client_async .run (run .id ).get ()
108
+ run = ActorRun .model_validate (updated_run )
109
+
110
+ try :
111
+ assert run .status == ActorJobStatus .SUCCEEDED
112
+ assert run .charged_event_counts == {'foobar' : 2 }
113
+ break
114
+ except AssertionError :
115
+ if is_last_attempt :
116
+ raise
0 commit comments