Repository navigation
Commit fc35b85
authored
test: deflake recurring task test and fix tests hanging on Python 3.10 (#2287)
Two ubuntu / Python 3.10 CI failures on master.
`test_recurring_task.py::test_execution` slept 200 ms and expected at
least 3 calls at a 30 ms delay, but a slow runner got 1
([run](https://github.com/apify/crawlee-python/actions/runs/38214082347/job/114694625489)).
It now waits for the third call with a 5 s timeout and no longer needs
`run_alone`.
A worker hung in a fixture teardown and the job ran until GitHub
cancelled it after 6 hours
([run](https://github.com/apify/crawlee-python/actions/runs/38172798916/job/114568777725)).
The cause is in `backports.asyncio.runner`, which pytest-asyncio uses on
3.10. `Runner.run(coro, context=...)` patches `contextvars.copy_context`
process-wide while it creates the task, so the test server's thread can
pick up the fixture's context. When both threads enter it at once,
`Context.run` raises `cannot enter context: ... is already entered`, the
task step is dropped, and the teardown waits forever. On Python 3.10,
`pytest-asyncio` is pinned to 1.0.x, the last release before it started
using the backports runner. That pin also brings in pytest 8, and ty
can't type-check `pytest.skip()` with it, so the six runtime skips in
the storage tests raise `pytest.skip.Exception` instead.
For any future hang, `timeout_method = "thread"` kills the stuck worker
(the default signal method never fired in the 6 h run), and
`faulthandler_timeout = 600` dumps every thread's stack into the log.
The job-level cap is in apify/workflows#333.
*✍️ Drafted by Claude Code*1 parent ca71cd2 commit fc35b85
6 files changed
Lines changed: 144 additions & 73 deletions
File tree
- tests/unit
- _utils
- storages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
| |||
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
270 | 278 | | |
271 | 279 | | |
272 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | | - | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 55 | + | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
| 933 | + | |
934 | 934 | | |
935 | 935 | | |
936 | 936 | | |
| |||
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | | - | |
| 1019 | + | |
1020 | 1020 | | |
1021 | 1021 | | |
1022 | 1022 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
997 | | - | |
| 997 | + | |
998 | 998 | | |
999 | 999 | | |
1000 | 1000 | | |
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | | - | |
| 1083 | + | |
1084 | 1084 | | |
1085 | 1085 | | |
1086 | 1086 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1279 | 1279 | | |
1280 | 1280 | | |
1281 | 1281 | | |
1282 | | - | |
| 1282 | + | |
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
| |||
1405 | 1405 | | |
1406 | 1406 | | |
1407 | 1407 | | |
1408 | | - | |
| 1408 | + | |
1409 | 1409 | | |
1410 | 1410 | | |
1411 | 1411 | | |
| |||
0 commit comments