Skip to content

Commit b0a4173

Browse files
committed
CSHARP-2418: Add test that reads ignore db/collection readConcern in transaction
1 parent 1d0363e commit b0a4173

File tree

8 files changed

+1081
-5
lines changed

8 files changed

+1081
-5
lines changed

tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenBulkWriteTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ private void AssertResultAspect(string name, BsonValue expectedValue)
106106
case "insertedIds":
107107
_result.InsertedCount.Should().Be(expectedValue.AsBsonDocument.ElementCount);
108108
break;
109+
110+
case "insertedCount":
111+
_result.InsertedCount.Should().Be(expectedValue.ToInt64());
112+
break;
109113

110114
case "matchedCount":
111115
_result.MatchedCount.Should().Be(expectedValue.ToInt64());

tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenRunCommandTest.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public sealed class JsonDrivenRunCommandTest : JsonDrivenDatabaseTest
2727
{
2828
// private fields
2929
private BsonDocument _command;
30+
private ReadConcern _readConcern = new ReadConcern();
3031
private ReadPreference _readPreference;
3132
private BsonDocument _result;
3233
private IClientSessionHandle _session;
@@ -40,7 +41,8 @@ public JsonDrivenRunCommandTest(IMongoDatabase database, Dictionary<string, obje
4041
// public methods
4142
public override void Arrange(BsonDocument document)
4243
{
43-
JsonDrivenHelper.EnsureAllFieldsAreValid(document, "name", "object", "command_name", "arguments", "result");
44+
var expectedNames = new[] {"name", "object", "command_name", "arguments", "result", "databaseOptions"};
45+
JsonDrivenHelper.EnsureAllFieldsAreValid(document, expectedNames);
4446
base.Arrange(document);
4547

4648
if (document.Contains("command_name"))
@@ -65,23 +67,31 @@ protected override void CallMethod(CancellationToken cancellationToken)
6567
{
6668
if (_session == null)
6769
{
68-
_result = _database.RunCommand<BsonDocument>(_command, _readPreference, cancellationToken);
70+
_result = _database
71+
.WithReadConcern(_readConcern)
72+
.RunCommand<BsonDocument>(_command, _readPreference, cancellationToken);
6973
}
7074
else
7175
{
72-
_result = _database.RunCommand<BsonDocument>(_session, _command, _readPreference, cancellationToken);
76+
_result = _database
77+
.WithReadConcern(_readConcern)
78+
.RunCommand<BsonDocument>(_session, _command, _readPreference, cancellationToken);
7379
}
7480
}
7581

7682
protected override async Task CallMethodAsync(CancellationToken cancellationToken)
7783
{
7884
if (_session == null)
7985
{
80-
_result = await _database.RunCommandAsync<BsonDocument>(_command, _readPreference, cancellationToken);
86+
_result = await _database
87+
.WithReadConcern(_readConcern)
88+
.RunCommandAsync<BsonDocument>(_command, _readPreference, cancellationToken).ConfigureAwait(false);
8189
}
8290
else
8391
{
84-
_result = await _database.RunCommandAsync<BsonDocument>(_session, _command, _readPreference, cancellationToken);
92+
_result = await _database
93+
.WithReadConcern(_readConcern)
94+
.RunCommandAsync<BsonDocument>(_session, _command, _readPreference, cancellationToken).ConfigureAwait(false);
8595
}
8696
}
8797

@@ -92,6 +102,13 @@ protected override void SetArgument(string name, BsonValue value)
92102
case "command":
93103
_command = value.AsBsonDocument;
94104
return;
105+
106+
case "databaseOptions":
107+
if (value.AsBsonDocument.TryGetValue("readConcern", out var readConcernValue))
108+
{
109+
_readConcern = ReadConcern.FromBsonDocument(readConcernValue.AsBsonDocument);
110+
}
111+
return;
95112

96113
case "readPreference":
97114
_readPreference = ReadPreference.FromBsonDocument(value.AsBsonDocument);

tests/MongoDB.Driver.Tests/Specifications/transactions/tests/bulk.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
},
185185
"result": {
186186
"deletedCount": 4,
187+
"insertedCount": 6,
187188
"insertedIds": {
188189
"0": 1,
189190
"3": 3,

tests/MongoDB.Driver.Tests/Specifications/transactions/tests/bulk.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ tests:
8484
filter: {_id: {$gte: 6}}
8585
result:
8686
deletedCount: 4
87+
insertedCount: 6
8788
insertedIds: {0: 1, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7}
8889
matchedCount: 7
8990
modifiedCount: 7

0 commit comments

Comments
 (0)