From 6f34f2f86b80c3a2326a0c085559cfb247cca142 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Mon, 2 Nov 2026 10:11:03 +0100 Subject: [PATCH] test: stabilize `test_actor_last_run` against concurrent run deletions --- tests/integration/test_actor.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_actor.py b/tests/integration/test_actor.py index fcae2ce0..b2408b4f 100644 --- a/tests/integration/test_actor.py +++ b/tests/integration/test_actor.py @@ -6,7 +6,7 @@ from datetime import UTC, datetime, timedelta from typing import TYPE_CHECKING -from .._utils import get_random_resource_name, maybe_await +from .._utils import get_random_resource_name, maybe_await, poll_until_condition from apify_client._models import ( ActorChargeEvent, ActorListItem, @@ -171,10 +171,14 @@ async def test_actor_last_run(client: ApifyClient | ApifyClientAsync) -> None: last_run_client = actor_client.last_run() assert last_run_client is not None - # Use the returned client to get the run - last_run = await maybe_await(last_run_client.get()) + # Parallel tests share this account and keep finishing and deleting hello-world runs, so "last" may + # resolve to a run deleted before the API serves it (404 -> None). Poll past that window. + last_run = await poll_until_condition( + lambda: maybe_await(last_run_client.get()), + lambda r: isinstance(r, Run) and r.started_at >= run.started_at, + ) assert isinstance(last_run, Run) - assert last_run.id is not None + assert last_run.started_at >= run.started_at finally: await maybe_await(client.run(run.id).delete())