CSHARP-6069: Add await to async tests missing await#2028
Conversation
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
|
Sage Bot can help with this pull request. Just |
There was a problem hiding this comment.
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
voidtoasync Task. - Added missing
awaitkeywords for*Asyncmethod calls in tests. - Added
using System.Threading.Tasks;where required by newTaskreturn 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.
There was a problem hiding this comment.
Here is a little more.
it should be in form of:
var exception = async ?
await Record.ExceptionAsync(() => ...) :
Record.Exception(() => ... );
|
Refactored |
…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.
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:
*Async methods now properly await them
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.