Skip to content

CSHARP-6069: Add await to async tests missing await#2028

Merged
BorisDog merged 2 commits into
mainfrom
sage-bot/CSHARP-6069/sage-CSHARP-6069-1780694910597
Jun 6, 2026
Merged

CSHARP-6069: Add await to async tests missing await#2028
BorisDog merged 2 commits into
mainfrom
sage-bot/CSHARP-6069/sage-CSHARP-6069-1780694910597

Conversation

@mongodb-sage-bot

Copy link
Copy Markdown
Contributor

Add await keyword to async method calls in test files that were
previously calling async methods without awaiting them. The affected
test methods are also changed from returning void to returning Task
with the async modifier.

Files changed:

  • OfTypeMongoCollectionTests.cs: All unit test methods that call
    *Async methods now properly await them
  • IMongoDatabaseExtensionsTests.cs: WatchAsync calls now awaited
  • IMongoClientExtensionsTests.cs: WatchAsync calls now awaited

Important

MongoDB Contribution Guidelines

This pull request was generated by sage-bot on behalf of boris.dogadov@mongodb.com (ticket assignee). The assignee must self-review the changes before requesting review from another engineer.
The assignee is not allowed to merge their own PR without approval from another engineer.

Add await keyword to async method calls in test files that were
previously calling async methods without awaiting them. The affected
test methods are also changed from returning void to returning Task
with the async modifier.

Files changed:
- OfTypeMongoCollectionTests.cs: All unit test methods that call
  *Async methods now properly await them
- IMongoDatabaseExtensionsTests.cs: WatchAsync calls now awaited
- IMongoClientExtensionsTests.cs: WatchAsync calls now awaited
@mongodb-sage-bot

Copy link
Copy Markdown
Contributor Author

Sage Bot can help with this pull request. Just @sage-bot in comments and I'll start working on changes in this branch.
Learn more about Sage Bot

@BorisDog BorisDog added the chore Non–user-facing code changes (tests, build scripts, etc.). label Jun 5, 2026
@BorisDog BorisDog marked this pull request as ready for review June 5, 2026 21:45
@BorisDog BorisDog requested a review from a team as a code owner June 5, 2026 21:45
@BorisDog BorisDog requested review from Copilot and sanych-sun June 5, 2026 21:45

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.

Pull request overview

This PR updates several test files to correctly await asynchronous driver calls, ensuring async execution paths are actually exercised and that test failures propagate reliably through xUnit.

Changes:

  • Converted affected xUnit theory tests from void to async Task.
  • Added missing await keywords for *Async method calls in tests.
  • Added using System.Threading.Tasks; where required by new Task return types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs Converts multiple theory tests to async Task and awaits previously un-awaited collection async calls.
tests/MongoDB.Driver.Tests/IMongoDatabaseExtensionsTests.cs Makes the watch extension test async and awaits WatchAsync calls before verification.
tests/MongoDB.Driver.Tests/IMongoClientExtensionsTests.cs Makes the watch extension test async and awaits WatchAsync calls before verification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sanych-sun sanych-sun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sanych-sun sanych-sun Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is a little more.
it should be in form of:

var exception = async ?
    await Record.ExceptionAsync(() => ...) : 
    Record.Exception(() => ... );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sage-bot please handle this comment.

@mongodb-sage-bot

mongodb-sage-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Refactored EstimatedDocumentCount_should_throw in OfTypeMongoCollectionTests.cs to use the async ? await Record.ExceptionAsync(...) : Record.Exception(...) ternary pattern instead of wrapping GetAwaiter().GetResult() inside a synchronous Record.Exception, as @sanych-sun requested.

…unt_should_throw

Refactor the test to use the idiomatic async ternary pattern with
Record.ExceptionAsync/Record.Exception instead of wrapping
GetAwaiter().GetResult() inside Record.Exception, as requested
by @sanych-sun in PR review.

@sanych-sun sanych-sun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@BorisDog BorisDog merged commit 0e2f6bf into main Jun 6, 2026
30 of 34 checks passed
@BorisDog BorisDog deleted the sage-bot/CSHARP-6069/sage-CSHARP-6069-1780694910597 branch June 6, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Non–user-facing code changes (tests, build scripts, etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants