Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions tests/integration/test_actor_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from apify._models import ActorRun

if TYPE_CHECKING:
from collections.abc import Iterable

from apify_client import ApifyClientAsync
from apify_client.clients import ActorClientAsync

Expand Down Expand Up @@ -63,20 +65,33 @@ async def ppe_actor(
return apify_client_async.actor(ppe_actor_build)


def retry_counter(retry_count: int) -> Iterable[tuple[bool, int]]:
for retry in range(retry_count - 1):
yield False, retry

yield True, retry_count - 1


async def test_actor_charge_basic(
ppe_actor: ActorClientAsync,
run_actor: RunActorFunction,
apify_client_async: ApifyClientAsync,
) -> None:
run = await run_actor(ppe_actor)

# Wait until the platform gets its act together and refetch
await asyncio.sleep(6)
updated_run = await apify_client_async.run(run.id).get()
run = ActorRun.model_validate(updated_run)
# Refetch until the platform gets its act together
for is_last_attempt, _ in retry_counter(30):
await asyncio.sleep(1)
updated_run = await apify_client_async.run(run.id).get()
run = ActorRun.model_validate(updated_run)

assert run.status == ActorJobStatus.SUCCEEDED
assert run.charged_event_counts == {'foobar': 4}
try:
assert run.status == ActorJobStatus.SUCCEEDED
assert run.charged_event_counts == {'foobar': 4}
break
except AssertionError:
if is_last_attempt:
raise


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

# Wait until the platform gets its act together and refetch
await asyncio.sleep(6)
updated_run = await apify_client_async.run(run.id).get()
run = ActorRun.model_validate(updated_run)

assert run.status == ActorJobStatus.SUCCEEDED
assert run.charged_event_counts == {'foobar': 2}
# Refetch until the platform gets its act together
for is_last_attempt, _ in retry_counter(30):
await asyncio.sleep(1)
updated_run = await apify_client_async.run(run.id).get()
run = ActorRun.model_validate(updated_run)

try:
assert run.status == ActorJobStatus.SUCCEEDED
assert run.charged_event_counts == {'foobar': 2}
break
except AssertionError:
if is_last_attempt:
raise
Loading