CSHARP-5740: Remove duplicate read concern for operations in snapshot sessions#1977
CSHARP-5740: Remove duplicate read concern for operations in snapshot sessions#1977kyra-rk wants to merge 4 commits intomongodb:mainfrom
Conversation
| public void GetReadConcernForSnapshotSession_should_return_expected_result( | ||
| bool isSnapshot, | ||
| int? snapshotTime, | ||
| string expectedResult) |
There was a problem hiding this comment.
I noticed there wasn't any coverage for GetReadConcernForSnapshotSession, so I added unit tests for it.
|
Side question: The transaction path in Code links:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses duplicated readConcern fields being sent when executing operations in snapshot sessions, by preventing normal operation-level read concern rendering when session.IsSnapshot is true and adding/adjusting tests to validate the behavior.
Changes:
- Update
ReadConcernHelper.GetReadConcernForCommandto returnnullfor snapshot sessions (avoids emitting an additional readConcern from operation/collection settings). - Add/extend unit + wire-protocol tests to ensure only a single
readConcernis present and that snapshot sessions behave as expected. - Add an integration test covering a snapshot session against a collection configured with a non-default read concern.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/MongoDB.Driver.Tests/ReadConcernIntegrationTests.cs | Adds an integration test ensuring snapshot sessions don’t cause duplicated readConcern on find. |
| tests/MongoDB.Driver.Tests/Core/WireProtocol/CommandWriteProtocolTests.cs | Adds protocol-level assertions that commands contain exactly one readConcern in snapshot/transaction scenarios. |
| tests/MongoDB.Driver.Tests/Core/Operations/ReadConcernHelperTests.cs | Adds coverage for snapshot-session read concern helper behavior and expands connection/session test helpers. |
| src/MongoDB.Driver/Core/Operations/ReadConcernHelper.cs | Changes GetReadConcernForCommand to suppress operation readConcern when session.IsSnapshot. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| result.Should().HaveCount(1); | ||
|
|
||
| var findEvent = eventCapturer.Events.OfType<CommandStartedEvent>().First(); | ||
| findEvent.Command["readConcern"]["level"].AsString.Should().Be("snapshot"); |
There was a problem hiding this comment.
Hmm this is a good point, I will revise
|
|
||
| var command = new BsonDocument | ||
| { | ||
| { "find", "testCollection" } |
There was a problem hiding this comment.
I will edit the name to be Execute_should_send_only_one_readConcern_for_snapshot_session_with_find_command
There was a problem hiding this comment.
I actually agree with this comment, and I think that this code could pass even without your fix.
You need to add a read concern in the operation, otherwise there won't be a duplicate in any case.
There was a problem hiding this comment.
Reading this more.... I'm not sure we're verifying anything here. The operation does not have a read concern, as we're not adding it (and that's what we want) and we're just verifying that a readConcern is added, but that's a different issue than the one in this ticket.
I think that the unit test you wrote, plus eventually the integration tests would be enough, and these two tests can be removed.
There was a problem hiding this comment.
Agreed, will remove!
| namespace MongoDB.Driver.Tests | ||
| { | ||
| [Trait("Category", "Integration")] | ||
| public class ReadConcernIntegrationTests : LoggableTestClass |
There was a problem hiding this comment.
I like the idea of this integration test but but sure if we should keep this name for the file/class or we should change it. Or if it makes sense to move this test in some other file, but none of the ones we have seems to be relevant.
This is more of an open question/comment.
There was a problem hiding this comment.
Hmm yeah I honestly was struggling to find a good place for it. Maybe we can keep the name and move it under Core so it's next to tests/MongoDB.Driver.Tests/Core/ReadConcernTests.cs? I'm also not apposed to renaming it, but ReadConcern seemed more general than focusing on the Snapshot part
I think this is worth filing a ticket for. And if you got the time, creating a reproducible test that verifies this issue would be incredibly useful. |
|
Overall this PR seems correct to me, added @sanych-sun as the reviewer to get another eye. |
No description provided.