Fix test_data_file race condition on Python 3.14 free-threaded#12170
Fix test_data_file race condition on Python 3.14 free-threaded#12170Dreamsorcerer merged 4 commits intoaio-libs:masterfrom
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12170 +/- ##
=======================================
Coverage 98.77% 98.78%
=======================================
Files 128 128
Lines 45321 45326 +5
Branches 2405 2405
=======================================
+ Hits 44768 44776 +8
+ Misses 393 390 -3
Partials 160 160
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Backport to 3.13: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 2d03bc4 on top of patchback/backports/3.13/2d03bc45722f4153c2a993f084ecac04023d54c4/pr-12170 Backporting merged PR #12170 into master
🤖 @patchback |
Backport to 3.14: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 2d03bc4 on top of patchback/backports/3.14/2d03bc45722f4153c2a993f084ecac04023d54c4/pr-12170 Backporting merged PR #12170 into master
🤖 @patchback |
What do these changes do?
This PR fixes a flaky test (
test_data_file) that fails on Python 3.14 free-threaded (3.14t) builds.The test asserts
asyncio.isfuture(req._writer)immediately afterawait req._send(conn). However, on Python 3.12+,asyncio.Taskacceptseager_start=True. Because the 2-byte file payload in this test is exceptionally small, the eagerly-started task completes synchronously during_send().When
task.done()handles this,req._writeris left asNone, causing the assertion to fail (e.g.assert False + where False = asyncio.isfuture(None)).This PR applies the exact same mock strategy used by the sibling test
test_data_stream. We mock the_write_bytesmethod to executeawait asyncio.sleep(0), guaranteeing the task yields back to the event loop. This ensuresreq._writerholds a pending Future when the assertion fires.The fixed test has failed in PRs #12089 and #12153, for example.
Are there changes in behavior for the user?
No user-facing changes. This strictly addresses test flakiness in the CI environment.
Is it a substantial burden for the maintainers to support this?
No. This follows the exact same pattern already used in the same test file.
Related issue number
N/A.
Checklist
CONTRIBUTORS.txtCHANGES/folder