Repository navigation
Commit 91a79c7
authored
test: fix Stagehand binary cache race in plugin tests (#2460)
`test_methods_raise_error_when_not_active` creates a real
`AsyncStagehand`, which copies the Stagehand binary into the per-user
cache. It did not use the `stagehand_binary` fixture, so it skipped the
`FileLock` added in #2418. With `--dist worksteal`, it can run on one
worker while another worker is inside the locked fixture. Both write the
same `.tmp` file and then rename it, and the rename fails with `WinError
32` on Windows ([failed
run](https://github.com/apify/crawlee-python/actions/runs/44047531630/job/133916850608))
or `FileNotFoundError` on Linux.
Changes:
- Every test in `test_stagehand_browser_plugin.py` uses the
`stagehand_binary` fixture through a module-level `pytestmark`, so a new
test in the file can't skip the lock.
- The lock file sits next to the per-user cache, not in the pytest
session's temp directory. Two pytest sessions running at the same time
(for example, in two worktrees) share one lock.
- The fixture resolves the binary for `stagehand.__version__`, the
version `AsyncStagehand` uses. Before, a set `STAGEHAND_VERSION` made it
fill a different cache directory than the client.
Each change was checked locally with a 3 s delay patched in between the
write and the rename, and a fresh cache for each run:
- Plugin tests: 20 of 20 runs failed before, 0 of 100 after.
- Two concurrent pytest sessions: 3 of 3 failed with the old lock path,
0 of 3 with the new one.
- `STAGEHAND_VERSION` set: 3 of 3 failed before, 0 of 3 after.
*✍️ Drafted by Claude Code*1 parent 4275339 commit 91a79c7
2 files changed
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| |||
0 commit comments