Skip to content

PYTHON-5975 Fix missing await calls in async test suite - #3029

Open
blink1073 wants to merge 2 commits into
mongodb:mainfrom
blink1073:claude/python-5975-jira-ticket-171e7d
Open

PYTHON-5975 Fix missing await calls in async test suite#3029
blink1073 wants to merge 2 commits into
mongodb:mainfrom
blink1073:claude/python-5975-jira-ticket-171e7d

Conversation

@blink1073

@blink1073 blink1073 commented Sep 1, 2026

Copy link
Copy Markdown
Member

PYTHON-5975

Changes in this PR

  • Replaced the raw threading.Thread in test_reset_during_update_pool with ExceptionCatchingTask, so the pool-reset loop actually runs.
  • Dropped that test's require_sync, which existed only because of the raw thread.
  • Asserted the background task's exception, so a broken pool-reset loop fails the test instead of hanging it.
  • Fixed InsertEventListener.succeeded() to run its configureFailPoint command instead of dropping an unawaited coroutine.
  • Consumed that command's exception through a done callback.

Test Plan

  • test_reset_during_update_pool went from SKIPPED to passing in the async suite.
  • test_returns_original_error_code passes, and I confirmed the listener's fail point branch executes rather than passing vacuously.
  • Both suites pass against a local replica set (9.1.0): sync 140 passed / 11 skipped, async 132 passed / 19 skipped.
  • just lint, just synchro, and mypy --config-file mypy_test.ini are clean on all four files.
  • Unverified: the listener's create_task branch, which its own require_sync still gates. A synchronous monitoring callback cannot await, so nothing orders the fail point ahead of the retry it targets.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? Test-only fix, no user-facing change.
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s). Static-check follow-up noted on PYTHON-5976.

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@blink1073
blink1073 force-pushed the claude/python-5975-jira-ticket-171e7d branch from 068b8dc to b182c9b Compare September 1, 2026 11:58
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Two async test bodies discarded coroutines instead of awaiting them, so
the behavior under test never ran. test_reset_during_update_pool now
drives its pool-reset loop with the ExceptionCatchingTask helper instead
of a raw threading.Thread, which lets it drop require_sync. The
retryable-writes listener schedules its fail point command as a task
because a synchronous monitoring callback cannot await.
@blink1073
blink1073 force-pushed the claude/python-5975-jira-ticket-171e7d branch from b182c9b to 1855b57 Compare September 3, 2026 18:53
@blink1073
blink1073 requested a lite review from Copilot September 3, 2026 18:56

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

🟡 Changes recommended

A newly created asyncio task in the async command listener is not observed/exception-consumed, which can hide failures or produce “Task exception was never retrieved” warnings.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes missing/incorrect awaiting in the async test suite so tests do real work (instead of silently dropping coroutines) and surface background-task failures deterministically.

Changes:

  • Updates test_reset_during_update_pool (sync + async suites) to use ExceptionCatchingTask so the pool-reset loop actually runs and failures are asserted.
  • Removes the require_sync gating on test_reset_during_update_pool so it executes in the async suite.
  • Fixes InsertEventListener.succeeded() in the async suite to avoid discarding an unawaited admin.command(...) coroutine by scheduling it with create_task.
File summaries
File Description
test/test_retryable_writes.py Refactors failPoint configuration in InsertEventListener.succeeded() to avoid dropped work and align sync/async branching.
test/test_client.py Replaces a bespoke reset-thread with ExceptionCatchingTask and asserts background errors; removes sync-only gating.
test/asynchronous/test_retryable_writes.py Schedules async failPoint configuration with create_task instead of dropping an unawaited coroutine.
test/asynchronous/test_client.py Uses ExceptionCatchingTask for async pool-reset loop so it runs concurrently and test failures are surfaced.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/asynchronous/test_retryable_writes.py
A done callback stores the scheduled fail point command's exception on
the listener, and test_returns_original_error_code asserts it stayed
None. An unobserved task exception otherwise leaves the test passing and
surfaces only as a "Task exception was never retrieved" warning.

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

🟢 Approval recommended

The changes are test-only and correctly make previously dropped async work observable, with only minor maintainability follow-ups suggested.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread test/asynchronous/test_retryable_writes.py
Comment thread test/test_retryable_writes.py
@blink1073
blink1073 marked this pull request as ready for review September 4, 2026 23:38
@blink1073
blink1073 requested a review from a team as a code owner September 4, 2026 23:38
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.

2 participants