Skip to content

Commit 47a7a69

Browse files
vdusekclaude
andauthored
fix: guard integration test resource names against 63-char API limit (#729)
## Summary - Adds a 63-character API name limit guard to `get_random_resource_name`, following the approach from `apify-sdk-python` - Fixes flaky `test_schedule_create_and_get[async]` caused by name collisions with stale schedules from cancelled CI runs ## Failed CI runs - https://github.com/apify/apify-client-python/actions/runs/24454251436/job/71450645691 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 93dd16e commit 47a7a69

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/integration/_utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ def get_random_string(length: int = 10) -> str:
6464
return ''.join(secrets.choice(string.ascii_letters) for _ in range(length))
6565

6666

67-
def get_random_resource_name(resource: str) -> str:
68-
"""Generate a random resource name for test resources."""
69-
return f'python-client-test-{resource}-{get_random_string(5)}'
67+
def get_random_resource_name(label: str) -> str:
68+
"""Generate a unique resource name containing the given label.
69+
70+
Ensures the generated name does not exceed the API limit of 63 characters.
71+
"""
72+
name_template = 'python-client-test-{}-{}'
73+
template_length = len(name_template.format('', ''))
74+
api_name_limit = 63
75+
random_id_length = 8
76+
label_length_limit = api_name_limit - template_length - random_id_length
77+
78+
label = label.replace('_', '-')
79+
assert len(label) <= label_length_limit, f'Max label length is {label_length_limit}, but got {len(label)}'
80+
81+
return name_template.format(label, get_crypto_random_object_id(random_id_length))
7082

7183

7284
@overload

0 commit comments

Comments
 (0)