Skip to content

Conversation

@sanych-sun
Copy link
Member

@sanych-sun sanych-sun commented Nov 14, 2025

Consolidate Stream extension methods + improve code coverage.
Includes fix for Tailable_cursor_should_be_able_to_be_cancelled_from_a_different_thread_with_expected_result flaky test.

@sanych-sun sanych-sun requested a review from BorisDog November 14, 2025 02:07
@sanych-sun sanych-sun requested a review from a team as a code owner November 14, 2025 02:08
@sanych-sun sanych-sun added the chore Non–user-facing code changes (tests, build scripts, etc.). label Nov 14, 2025
@BorisDog BorisDog requested a review from Copilot November 14, 2025 20:09
Copilot finished reviewing on behalf of BorisDog November 14, 2025 20:13
Copy link
Contributor

Copilot AI left a comment

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 refactors stream extension methods to consolidate implementations and avoid ThreadPool-dependent I/O methods in the synchronous API. The main changes involve replacing the old API that used OperationContext and TimeSpan parameters with a cleaner API that uses int timeoutMs and CancellationToken parameters directly.

Key Changes:

  • Consolidated stream extension methods with separate timeout handling for sync and async operations
  • Replaced TimeSpan timeout parameters with int timeoutMs (milliseconds) for consistency
  • Improved test coverage by adding dedicated tests for byte array overloads of WriteBytes methods

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/MongoDB.Driver/Core/Misc/StreamExtensionMethods.cs Complete refactoring of ReadBytes/WriteBytes extension methods with new timeout handling mechanism; sync methods now use Timer-based approach while async methods use Task.WhenAny pattern
tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs Updated all tests to use new API signatures; added comprehensive test coverage for byte array WriteBytes methods; renamed tests for better clarity
src/MongoDB.Driver/GridFS/GridFSBucket.cs Updated ReadBytes/ReadBytesAsync calls to use new API with named cancellationToken parameter
src/MongoDB.Driver/Core/Connections/BinaryConnection.cs Updated ReadBytes/WriteBytes calls with TimeSpan-to-milliseconds conversion at call sites
src/MongoDB.Driver/Core/Connections/Socks5Helper.cs Updated ReadBytes/ReadBytesAsync calls to use new API with named cancellationToken parameter
src/MongoDB.Driver/Core/Compression/SnappyCompressor.cs Simplified ReadBytes calls by removing unnecessary timeout parameters for in-memory operations

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

public async Task WriteBytes_with_byte_buffer_should_throw_when_buffer_is_null([Values(true, false)]bool async)
{
var stream = new Mock<Stream>().Object;
byte[] buffer = null;
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The test method is named WriteBytes_with_byte_buffer_should_throw_when_buffer_is_null but it's testing the byte array overload instead of the IByteBuffer overload. The variable should be declared as IByteBuffer buffer = null; to properly test the intended method.

Suggested change
byte[] buffer = null;
IByteBuffer buffer = null;

Copilot uses AI. Check for mistakes.
Comment on lines +287 to +290
catch (Exception)
{
// suppress any exception
}
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

Generic catch clause.

Suggested change
catch (Exception)
{
// suppress any exception
}
catch (ObjectDisposedException)
{
// suppress ObjectDisposedException
}
catch (IOException)
{
// suppress IOException
}

Copilot uses AI. Check for mistakes.
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.

1 participant