Skip to content

Commit b13af58

Browse files
authored
test: Give Apify builds more time in scheduled e2e templates test (#1909)
## Summary Two related scheduled e2e failures, both fixed by giving Apify builds more time to complete. ### 1. Stagehand rebuild: `wait_for_finish=600` was silently clipped to 60s The scheduled stagehand tests have been failing on every run since [#1900](#1900) added the post-`env_vars.create` rebuild ([example](https://github.com/apify/crawlee-python/actions/runs/26263684679/job/77302398839)): ``` apify_client.errors.ApifyApiError: The build has not finished or was not successful. ``` `ActorClientAsync.build()`'s `wait_for_finish` parameter is clipped server-side to a max of 60s ("By default it is 0, the maximum value is 60"). A stagehand build (playwright + browser deps) does not finish in 60s, so `actor.build()` returned a still-`PROCESSING` build and `actor.start(build=build_number)` was rejected. **Fix:** After triggering the rebuild, poll client-side via `client.build(<id>).wait_for_finish(wait_secs=900)` — which uses long-poll requests and actually waits up to the requested duration — then assert `status == 'SUCCEEDED'` before passing the build to `actor.start()`. ### 2. `apify push` 120s timeout was too tight for heavier templates The `poetry-curl-impersonate-adaptive-parsel` variant times out on every rerun ([example](https://github.com/apify/crawlee-python/actions/runs/26263684679/job/77302398558)): ``` subprocess.TimeoutExpired: Command '['apify', 'push']' timed out after 120 seconds ``` `apify push` waits server-side for the Docker build to finish before returning. The captured stderr shows a ~550 MB base image mid-download when the timeout fires — the CLI isn't hung, the build is just legitimately slower than 120s for heavier templates. Job total (522s ≈ 4 × 120s) confirms every rerun hits the same wall, so retries don't help. **Fix:** Bump all three apify-cli `subprocess.run` timeouts (`login`, `init`, `push`) from 120s to 600s. The 1800s `pytest-timeout` per test still bounds a truly hung CLI; `@pytest.mark.flaky(reruns=3)` still covers transient network/CLI flakes.
1 parent 41433a3 commit b13af58

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

tests/e2e/project_template/test_static_crawlers_templates.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ async def test_static_crawler_actor_at_apify(
9090
capture_output=True,
9191
check=True,
9292
cwd=tmp_path / actor_name,
93-
timeout=120,
93+
timeout=600,
9494
)
9595
subprocess.run( # noqa: ASYNC221, S603
9696
['apify', 'init', '-y', actor_name], # noqa: S607
9797
capture_output=True,
9898
check=True,
9999
cwd=tmp_path / actor_name,
100-
timeout=120,
100+
timeout=600,
101101
)
102102

103103
build_process = subprocess.run( # noqa: ASYNC221
@@ -108,7 +108,7 @@ async def test_static_crawler_actor_at_apify(
108108
# Prevent git from walking up into the surrounding project's .git/ when running under
109109
# a basetemp inside the repo (see --basetemp in the e2e-templates-tests poe task).
110110
env={**os.environ, 'GIT_CEILING_DIRECTORIES': str(tmp_path)},
111-
timeout=120,
111+
timeout=600,
112112
)
113113
# Get actor ID from build log
114114
actor_id_regexp = re.compile(r'https:\/\/console\.apify\.com\/actors\/(.*)#\/builds\/\d*\.\d*\.\d*')
@@ -132,8 +132,17 @@ async def test_static_crawler_actor_at_apify(
132132
if crawler_type == 'stagehand':
133133
env_vars = actor.version('0.0').env_vars()
134134
await env_vars.create(name='OPENAI_API_KEY', value=os.environ['OPENAI_API_KEY'], is_secret=True)
135-
rebuild = await actor.build(version_number='0.0', wait_for_finish=600)
136-
build_number = rebuild['buildNumber']
135+
# `ActorClientAsync.build`'s `wait_for_finish` parameter is capped server-side at 60s,
136+
# which is shorter than a stagehand build (playwright + browser deps). Trigger the build,
137+
# then poll client-side via `BuildClientAsync.wait_for_finish` until it reaches a terminal
138+
# status, and assert it succeeded before starting the run.
139+
rebuild = await actor.build(version_number='0.0')
140+
finished_build = await client.build(rebuild['id']).wait_for_finish(wait_secs=900)
141+
assert finished_build is not None, 'Stagehand rebuild did not reach a terminal status within 900s.'
142+
assert finished_build['status'] == 'SUCCEEDED', (
143+
f'Stagehand rebuild did not succeed: status={finished_build["status"]!r}, build={finished_build}'
144+
)
145+
build_number = finished_build['buildNumber']
137146

138147
started_run_data = await actor.start(memory_mbytes=8192, build=build_number)
139148
actor_run = client.run(started_run_data['id'])

0 commit comments

Comments
 (0)