Skip to content

Commit f647078

Browse files
committed
Added prose test
1 parent ee85c62 commit f647078

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

specifications/sessions/tests/snapshot-sessions.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,24 @@
10611061
}
10621062
]
10631063
},
1064+
{
1065+
"name": "find",
1066+
"object": "collection0",
1067+
"arguments": {
1068+
"session": "session2",
1069+
"filter": {}
1070+
},
1071+
"expectResult": [
1072+
{
1073+
"_id": 1,
1074+
"x": 11
1075+
},
1076+
{
1077+
"_id": 2,
1078+
"x": 11
1079+
}
1080+
]
1081+
},
10641082
{
10651083
"name": "find",
10661084
"object": "collection0",
@@ -1115,6 +1133,20 @@
11151133
"databaseName": "database0"
11161134
}
11171135
},
1136+
{
1137+
"commandStartedEvent": {
1138+
"command": {
1139+
"find": "collection0",
1140+
"readConcern": {
1141+
"level": "snapshot",
1142+
"atClusterTime": {
1143+
"$$matchesEntity": "savedSnapshotTime"
1144+
}
1145+
}
1146+
},
1147+
"databaseName": "database0"
1148+
}
1149+
},
11181150
{
11191151
"commandStartedEvent": {
11201152
"command": {

specifications/sessions/tests/snapshot-sessions.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ tests:
378378
fieldName: x
379379
filter: {}
380380
session: session0
381-
expectResult: [ 11 ]
381+
expectResult: [ 11 ]
382382
expectEvents:
383383
- client: client0
384384
events:
@@ -508,6 +508,16 @@ tests:
508508
sessionOptions:
509509
snapshot: true
510510
snapshotTime: *savedSnapshotTime
511+
- name: find
512+
object: collection0
513+
arguments:
514+
session: session2
515+
filter: {}
516+
expectResult:
517+
- { _id: 1, x: 11 }
518+
- { _id: 2, x: 11 }
519+
## Calling find again to verify that atClusterTime/snapshotTime has not been modified after the first query
520+
## as it would happen if snapshotTime had not been specified
511521
- name: find
512522
object: collection0
513523
arguments:
@@ -540,7 +550,14 @@ tests:
540550
find: collection0
541551
readConcern:
542552
level: snapshot
543-
atClusterTime: { $$matchesEntity: savedSnapshotTime }
553+
atClusterTime: { $$matchesEntity: *savedSnapshotTime }
554+
databaseName: database0
555+
- commandStartedEvent:
556+
command:
557+
find: collection0
558+
readConcern:
559+
level: snapshot
560+
atClusterTime: { $$matchesEntity: *savedSnapshotTime }
544561
databaseName: database0
545562
- commandStartedEvent:
546563
command:

src/MongoDB.Driver/MongoClient.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,18 @@ private RenderArgs<BsonDocument> GetRenderArgs()
622622

623623
private IClientSessionHandle StartSession(ClientSessionOptions options)
624624
{
625-
if (options != null && options.Snapshot && options.CausalConsistency == true)
625+
if (options != null)
626626
{
627-
throw new NotSupportedException("Combining both causal consistency and snapshot options is not supported.");
628-
}
627+
if (options.SnapshotTime != null && !options.Snapshot)
628+
{
629+
throw new NotSupportedException("Specifying a snapshot time requires snapshot to be true.");
630+
}
629631

630-
//TODO Throw an exception if SnapshotTime is set and Snapshot is not true.
632+
if (options.Snapshot && options.CausalConsistency == true)
633+
{
634+
throw new NotSupportedException("Combining both causal consistency and snapshot options is not supported.");
635+
}
636+
}
631637

632638
options ??= new ClientSessionOptions();
633639
if (_settings.Timeout.HasValue && options.DefaultTransactionOptions?.Timeout == null)

tests/MongoDB.Driver.Tests/Specifications/sessions/SessionsProseTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,24 @@ public void Ensure_cluster_times_are_not_gossiped_on_SDAM_commands()
357357
commandStartedEvents[0].Command["$clusterTime"].Should().Be(clusterTime);
358358
}
359359

360+
[Fact]
361+
public void If_SnapshotTime_is_set_Snapshot_must_be_true()
362+
{
363+
RequireServer.Check();
364+
365+
var sessionOptions = new ClientSessionOptions
366+
{
367+
Snapshot = false,
368+
SnapshotTime = new BsonTimestamp(1, 1)
369+
};
370+
371+
var mongoClient = DriverTestConfiguration.Client;
372+
373+
var exception = Record.Exception(() => mongoClient.StartSession(sessionOptions));
374+
exception.Should().BeOfType<NotSupportedException>();
375+
}
376+
377+
360378
private sealed class MongocryptdContext : IDisposable
361379
{
362380
public IMongoClient MongoClient { get; }

0 commit comments

Comments
 (0)