|
21 | 21 | using MongoDB.Bson;
|
22 | 22 | using MongoDB.Bson.TestHelpers;
|
23 | 23 | using MongoDB.Driver.Core;
|
| 24 | +using MongoDB.Driver.Core.Clusters; |
24 | 25 | using MongoDB.Driver.Core.Events;
|
25 | 26 | using MongoDB.Driver.Core.Misc;
|
26 | 27 | using MongoDB.Driver.Core.TestHelpers.Logging;
|
@@ -302,6 +303,55 @@ public async Task Ensure_server_session_are_allocated_only_on_connection_checkou
|
302 | 303 | await eventsTask.WithTimeout(1000);
|
303 | 304 | }
|
304 | 305 |
|
| 306 | + // https://specifications.readthedocs.io/en/latest/sessions/tests/#20-drivers-do-not-gossip-clustertime-on-sdam-commands |
| 307 | + [Fact] |
| 308 | + public void Ensure_cluster_times_are_not_gossiped_on_SDAM_commands() |
| 309 | + { |
| 310 | + RequireServer.Check().ClusterTypes(ClusterType.ReplicaSet, ClusterType.Sharded); |
| 311 | + |
| 312 | + var eventCapturer = new EventCapturer() |
| 313 | + .Capture<ServerHeartbeatStartedEvent>() |
| 314 | + .Capture<ServerHeartbeatSucceededEvent>() |
| 315 | + .Capture<CommandStartedEvent>(); |
| 316 | + |
| 317 | + using var c1 = DriverTestConfiguration.CreateMongoClient( |
| 318 | + settings => |
| 319 | + { |
| 320 | + settings.ClusterConfigurator = c => c.Subscribe(eventCapturer); |
| 321 | + settings.DirectConnection = true; |
| 322 | + settings.HeartbeatInterval = TimeSpan.FromMilliseconds(10); |
| 323 | + if (settings.Servers.Count() > 1) |
| 324 | + { |
| 325 | + settings.Servers = settings.Servers.Take(1); |
| 326 | + } |
| 327 | + }); |
| 328 | + |
| 329 | + var pingCommand = new BsonDocument("ping", 1); |
| 330 | + var pingResult = c1.GetDatabase("admin").RunCommand<BsonDocument>(pingCommand); |
| 331 | + |
| 332 | + var clusterTime = pingResult["$clusterTime"]; |
| 333 | + |
| 334 | + var c2 = DriverTestConfiguration.Client; |
| 335 | + c2.GetDatabase("test").GetCollection<BsonDocument>("test").InsertOne(new BsonDocument("advance", "$clusterTime")); |
| 336 | + |
| 337 | + eventCapturer.Clear(); |
| 338 | + |
| 339 | + eventCapturer.WaitForOrThrowIfTimeout( |
| 340 | + capturedEvents => |
| 341 | + { |
| 342 | + return capturedEvents |
| 343 | + .SkipWhile(e => e is not ServerHeartbeatStartedEvent) |
| 344 | + .Any(e => e is ServerHeartbeatSucceededEvent); |
| 345 | + }, TimeSpan.FromSeconds(1), "Didn't get any server heartbeat pairs"); |
| 346 | + |
| 347 | + c1.GetDatabase("admin").RunCommand<BsonDocument>(pingCommand); |
| 348 | + |
| 349 | + var commandStartedEvents = eventCapturer.Events.OfType<CommandStartedEvent>().ToArray(); |
| 350 | + commandStartedEvents.Length.Should().Be(1); |
| 351 | + commandStartedEvents[0].CommandName.Should().Be("ping"); |
| 352 | + commandStartedEvents[0].Command["$clusterTime"].Should().Be(clusterTime); |
| 353 | + } |
| 354 | + |
305 | 355 | private sealed class MongocryptdContext : IDisposable
|
306 | 356 | {
|
307 | 357 | public IMongoClient MongoClient { get; }
|
|
0 commit comments