Skip to content

Commit 97e00fe

Browse files
committed
test: make ppe_actor block on charge limit so run aborts deterministically
1 parent e2e50c5 commit 97e00fe

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tests/e2e/test_actor_charge.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ async def ppe_push_data_actor(
7474
@pytest_asyncio.fixture(scope='module', loop_scope='module')
7575
async def ppe_actor_build(make_actor: MakeActorFunction) -> str:
7676
async def main() -> None:
77+
import asyncio
7778
from dataclasses import asdict
7879

7980
async with Actor:
@@ -83,6 +84,12 @@ async def main() -> None:
8384
)
8485
Actor.log.info('Charged', extra=asdict(charge_result))
8586

87+
# When the charge limit is reached, the platform auto-aborts this run. That abort races with the
88+
# Actor's own clean exit, making the terminal status non-deterministic (SUCCEEDED or ABORTED). Block
89+
# here so the abort always wins and the run ends deterministically as ABORTED.
90+
if charge_result.event_charge_limit_reached:
91+
await asyncio.Event().wait()
92+
8693
actor_client = await make_actor('ppe', main_func=main)
8794

8895
await actor_client.update(
@@ -142,19 +149,17 @@ async def test_actor_charge_limit(
142149
) -> None:
143150
run = await run_actor(ppe_actor, max_total_charge_usd=Decimal('0.2'))
144151

145-
# Reaching `max_total_charge_usd` makes the platform auto-abort the run, racing with the Actor's clean exit, so
146-
# the terminal status is either SUCCEEDED or ABORTED. What matters is that the limit capped it at 2 events.
147-
terminal_statuses = {ActorJobStatus.SUCCEEDED, ActorJobStatus.ABORTED}
148-
152+
# Reaching `max_total_charge_usd` makes the platform auto-abort the run. The Actor blocks after hitting the
153+
# limit (see `ppe_actor_build`) so the abort always wins the race against its clean exit, hence ABORTED.
149154
# Refetch until the charged event counts propagate on the platform.
150155
run = await poll_until_condition(
151156
partial(_get_run, apify_client_async, run.id),
152-
lambda r: r.status in terminal_statuses and r.charged_event_counts == {'foobar': 2},
157+
lambda r: r.status == ActorJobStatus.ABORTED and r.charged_event_counts == {'foobar': 2},
153158
timeout=30,
154159
poll_interval=1,
155160
)
156161

157-
assert run.status in terminal_statuses
162+
assert run.status == ActorJobStatus.ABORTED
158163
assert run.charged_event_counts == {'foobar': 2}
159164

160165

0 commit comments

Comments
 (0)