Skip to content

test: make the serverless suite clean under -W error on 3.14 - #768

Merged
deanq merged 1 commit into
mainfrom
deanq/SLS-1129-py314-test-hygiene
Dec 2, 2026
Merged

deanq merged 1 commit into
mainfrom
deanq/SLS-1129-py314-test-hygiene

Conversation

@deanq

@deanq deanq commented Nov 29, 2026

Copy link
Copy Markdown
Member

Summary

Nine serverless tests failed on Python 3.14 (Linux) with -W error. They are test hygiene problems, not SDK bugs. This makes the suite clean there before 3.14 strictness is relied on in CI. It still passes on 3.10 and 3.13.

Root cause

  • AsyncMock stood in for synchronous APIs (Process.kill, StreamWriter.close), so calling them created coroutines that were never awaited.
  • Patching asyncio.wait_for with a side effect dropped the communicate() coroutine without awaiting it, which leaked into a later test.
  • An async function was patched where the patched asyncio.run never awaited it.
  • An aiohttp.ClientSession in a test was never closed.
  • A test used the deprecated asyncio.iscoroutinefunction.
  • backoff (third party) calls the same deprecated API when it decorates the download function.

Fix

  • MagicMock for synchronous parts, AsyncMock only for real coroutines, and assertions that the awaited ones were awaited.
  • The fake wait_for closes the coroutine it receives.
  • async with for the client session; inspect.iscoroutinefunction in the test.
  • One filterwarnings ignore scoped to the download test class, because the warning comes from backoff. pytest.ini is unchanged.

Tests

  • Linux 3.14, pytest tests/test_serverless -W error: 9 failed before, 686 passed after.
  • Linux 3.10 and 3.13: 686 passed. Full suite on macOS passes.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 22:41

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the serverless test-hygiene changes.

No open issues 🎉

What changed in this PR

This PR improves serverless test hygiene for Python 3.14 runs with -W error, without changing SDK runtime behavior.

Changes:

  • Match synchronous and asynchronous mocks to real APIs and strengthen cleanup assertions.
  • Close leaked coroutines and HTTP sessions, and replace deprecated coroutine inspection.
  • Add a download-test-class warning filter for the third-party backoff deprecation.
File Description
tests/​test_serverless/​test_utils/​test_download.py Scope the backoff warning exemption to the download test class.
tests/​test_serverless/​test_scale_mirror.py Avoid creating an unawaited fitness-check coroutine during mocked startup.
tests/​test_serverless/​test_modules/​test_http.py Close the client session with an async context manager.
tests/​test_serverless/​test_modules/​test_fitness/​test_system_checks.py Correct writer mocks, assert awaited closure, and use inspect.iscoroutinefunction.
tests/​test_serverless/​test_modules/​test_fitness/​test_gpu_integration.py Dispose of the coroutine received by the simulated timeout.
tests/​test_serverless/​test_modules/​test_fitness/​test_gpu_checks.py Correct process mocks and assert process termination and awaited reaping.

Review effort: Balanced

@deanq
deanq force-pushed the deanq/SLS-1129-py314-test-hygiene branch 2 times, most recently from f7ed211 to dfab4a6 Compare November 30, 2026 18:59
@deanq
deanq marked this pull request as ready for review December 1, 2026 17:43
@deanq
deanq force-pushed the deanq/SLS-1129-py314-test-hygiene branch from dfab4a6 to 7d8ed5c Compare December 1, 2026 17:47
Run with the plugin-default warning handling (-W error, unraisable
exceptions enabled), nine serverless tests failed on Python 3.14. They
were test hygiene problems, not SDK bugs:

- AsyncMock children for synchronous APIs (Process.kill, StreamWriter.close,
  fitness run_fitness_checks patch) produced never-awaited coroutines.
  Use MagicMock for the synchronous parts and assert the awaited ones.
- Patching asyncio.wait_for with a side effect leaked the un-awaited
  communicate() coroutine; the replacement now closes it.
- An aiohttp ClientSession was never closed; use async with.
- asyncio.iscoroutinefunction is deprecated; use inspect's.
- backoff (third party) still calls the deprecated asyncio API when
  decorating; ignore that single warning on the download test class only.
@deanq
deanq force-pushed the deanq/SLS-1129-py314-test-hygiene branch from 7d8ed5c to 94595c3 Compare December 1, 2026 19:29
@deanq
deanq requested a review from a team December 1, 2026 19:47
@justinwlin
justinwlin self-requested a review December 2, 2026 01:28
@justinwlin

justinwlin commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Kimi review posted: #768 (review)

How to ask for a K​imi review: GitHub: request @​justinwlin as a reviewer, or comment @​justinwlin w​atcher, review on the PR. Slack: DM @​justin.lin W​atcher, review <PR link>. New commits get an automatic re-review 30 min after the last push. Stop it: DM W​atcher, stop <PR link>.

@justinwlin justinwlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Kimi review, round 1

Verdict: Approved. 0 Critical, 0 High, 0 Medium, 1 Low → approved.

Next step: deanq merges.

Context: Fixes un-awaited coroutines and deprecated asyncio APIs in five serverless test files so the suite stays clean on Python 3.14 under -W error.

Findings

  1. Low: The PR body lists an aiohttp ClientSession fix ("use async with for the client session") that is not in this diff — test_http.py already had async with at the merge-base, so that fix shipped earlier. Please update the description; the other body claims check out.
Other reviewers, what was run, nits
  • Ran: python3.14 -m pytest tests/test_serverless -W error on macOS 3.14.6 → parent commit: 8 failed (un-awaited coroutines + the backoff asyncio.iscoroutinefunction deprecation); PR head: 747 passed, 1 skipped, 50s. The "fails before, clean after" claim reproduces (9 vs 8 and 686 vs 747 are platform differences).
  • Verified the class mark in test_download.py is load-bearing, not redundant: pytest.ini's global iscoroutinefunction ignore does not protect against command-line -W error (command-line filters outrank ini filters), and the download tests fail at the parent commit without the mark. The two agents' "redundant decorator" read is refuted by the run above.
  • Copilot review ("no open issues"): no actionable claims to engage.
  • Nit tests/test_serverless/test_utils/test_download.py:73-78: mark + comment duplicate _ignore_backoff_deprecation in tests/test_serverless/test_utils/test_cleanup.py:78-82 (same magic string twice plus pytest.ini:9); a shared helper or conftest-level mark would keep them in sync.
  • Nit tests/test_serverless/test_modules/test_fitness/test_gpu_integration.py:187: awaitable.close() would AttributeError if a Task/Future were ever passed to the patched asyncio.wait_for; safe today (gpu.py:151 passes a plain coroutine), a getattr(awaitable, "close", None) guard would make it robust.
  • Not checked: backoff's pinned version (the deprecation call comes from backoff decorating download_file in rp_download.py:147); exact Linux failure count.

To get a new review, re-request it or comment 'w​atcher, review'. If you push new commits, we review again by ourselves 30 minutes after the last push.

Kimi (moonshotai/Kimi-K3) · round 1 · 2 review agents (correctness, quality) · ~15 min · automated review, a human owns the final call. New commits are checked every 5 min and get an automatic re-review of the changes since this round. How to ask for a K​imi review: GitHub: request @​justinwlin as a reviewer, or comment @​justinwlin w​atcher, review on the PR. Slack: DM @​justin.lin W​atcher, review <PR link>. New commits get an automatic re-review 30 min after the last push. Stop it: DM W​atcher, stop <PR link>.

@deanq
deanq merged commit 1e3406a into main Dec 2, 2026
9 checks passed
@deanq
deanq deleted the deanq/SLS-1129-py314-test-hygiene branch December 2, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants