Skip to content

Commit b9439f2

Browse files
committed
test: deflake test_actor_create_update_delete against retried create conflict
1 parent af6d0f7 commit b9439f2

1 file changed

Lines changed: 30 additions & 20 deletions

File tree

tests/integration/test_actor.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Run,
2020
)
2121
from apify_client._resource_clients import BuildClient, BuildClientAsync
22+
from apify_client.errors import ConflictError
2223

2324
if TYPE_CHECKING:
2425
from apify_client import ApifyClient, ApifyClientAsync
@@ -88,27 +89,36 @@ async def test_actor_create_update_delete(client: ApifyClient | ApifyClientAsync
8889
actor_name = get_random_resource_name('actor')
8990

9091
# Create actor
91-
created_actor = await maybe_await(
92-
client.actors().create(
93-
name=actor_name,
94-
title='Test Actor',
95-
description='Test actor for integration tests',
96-
versions=[
97-
{
98-
'versionNumber': '0.1',
99-
'sourceType': 'SOURCE_FILES',
100-
'buildTag': 'latest',
101-
'sourceFiles': [
102-
{
103-
'name': 'main.js',
104-
'format': 'TEXT',
105-
'content': 'console.log("Hello")',
106-
}
107-
],
108-
}
109-
],
92+
try:
93+
created_actor = await maybe_await(
94+
client.actors().create(
95+
name=actor_name,
96+
title='Test Actor',
97+
description='Test actor for integration tests',
98+
versions=[
99+
{
100+
'versionNumber': '0.1',
101+
'sourceType': 'SOURCE_FILES',
102+
'buildTag': 'latest',
103+
'sourceFiles': [
104+
{
105+
'name': 'main.js',
106+
'format': 'TEXT',
107+
'content': 'console.log("Hello")',
108+
}
109+
],
110+
}
111+
],
112+
)
110113
)
111-
)
114+
except ConflictError:
115+
# The HTTP client retries requests on transient 5xx/network errors (at-least-once delivery), so a create
116+
# POST can commit server-side on one attempt yet still be retried; the retry then fails with a 409 on the
117+
# unique name it just took. Recover the Actor the first attempt created instead of flaking on this race.
118+
user = await maybe_await(client.user().get())
119+
assert user is not None
120+
created_actor = await maybe_await(client.actor(f'{user.username}/{actor_name}').get())
121+
112122
assert isinstance(created_actor, Actor)
113123
assert created_actor.id is not None
114124
assert created_actor.name == actor_name

0 commit comments

Comments
 (0)