Skip to content

Commit f7c56c4

Browse files
committed
More robust test result checking
1 parent 235078b commit f7c56c4

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

tests/integration/test_actor_charge.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from apify._models import ActorRun
1313

1414
if TYPE_CHECKING:
15+
from collections.abc import Iterable
16+
1517
from apify_client import ApifyClientAsync
1618
from apify_client.clients import ActorClientAsync
1719

@@ -63,20 +65,33 @@ async def ppe_actor(
6365
return apify_client_async.actor(ppe_actor_build)
6466

6567

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+
6675
async def test_actor_charge_basic(
6776
ppe_actor: ActorClientAsync,
6877
run_actor: RunActorFunction,
6978
apify_client_async: ApifyClientAsync,
7079
) -> None:
7180
run = await run_actor(ppe_actor)
7281

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)
7787

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
8095

8196

8297
async def test_actor_charge_limit(
@@ -86,10 +101,16 @@ async def test_actor_charge_limit(
86101
) -> None:
87102
run = await run_actor(ppe_actor, max_total_charge_usd=Decimal('0.2'))
88103

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

Comments
 (0)