Skip to content

test: deflake recurring task test and fix tests hanging on Python 3.10 - #2287

Merged
vdusek merged 8 commits into
masterfrom
test/deflake-recurring-task-infinite-scroll
Oct 13, 2026
Merged

vdusek merged 8 commits into
masterfrom
test/deflake-recurring-task-infinite-scroll

Conversation

@vdusek

@vdusek vdusek commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

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). 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). 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

@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Oct 12, 2026
@vdusek vdusek self-assigned this Oct 12, 2026
@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.06%. Comparing base (fe97ee8) to head (6e5401e).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2287      +/-   ##
==========================================
- Coverage   94.12%   94.06%   -0.06%     
==========================================
  Files         183      183              
  Lines       13570    13570              
==========================================
- Hits        12773    12765       -8     
- Misses        797      805       +8     
Flag Coverage Δ
unit 94.06% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek
vdusek marked this pull request as ready for review October 12, 2026 07:20
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Oct 12, 2026
@vdusek vdusek changed the title test: deflake recurring task test and kill hung tests with a thread timeout test: deflake recurring task test and avoid Python 3.10 unit test hangs Oct 13, 2026
@vdusek vdusek changed the title test: deflake recurring task test and avoid Python 3.10 unit test hangs test: deflake recurring task test and skip tests hanging on Python 3.10 Oct 13, 2026
@vdusek
vdusek requested a review from Mantisus October 13, 2026 09:02
@vdusek

vdusek commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Let's just skip the problematic tests on 3.10 + Linux, since the failures are caused by an upstream issue, and we will drop 3.10 support soon anyway.

@Mantisus Mantisus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread tests/unit/request_loaders/test_sitemap_request_loader.py Outdated

@apify-approval-mirror apify-approval-mirror Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mirroring approval from @Mantisus.

@apify-approval-mirror apify-approval-mirror Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mirroring approval from @Mantisus.

@vdusek vdusek changed the title test: deflake recurring task test and skip tests hanging on Python 3.10 test: deflake recurring task test and fix tests hanging on Python 3.10 Oct 13, 2026
@vdusek
vdusek merged commit fc35b85 into master Oct 13, 2026
36 of 37 checks passed
@vdusek
vdusek deleted the test/deflake-recurring-task-infinite-scroll branch October 13, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants