Skip to content

Commit b370f5f

Browse files
authored
CSHARP-3705: Updated spec testing code to handle hello, ignore tests related to not-yet-implemented load balancer support, and update sharded cluster tests to reflect new explain plan output from 5.0 sharded clusters. (#548)
1 parent d3f75f8 commit b370f5f

File tree

18 files changed

+92
-17
lines changed

18 files changed

+92
-17
lines changed

tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ private bool CanRunOn(ICluster cluster, BsonDocument requirement)
222222
{
223223
switch (item.Name)
224224
{
225+
case "authEnabled":
226+
{
227+
var actualAuthentication = CoreTestConfiguration.ConnectionString.Username != null;
228+
return actualAuthentication == item.Value.AsBoolean;
229+
}
225230
case "minServerVersion":
226231
{
227232
var actualVersion = CoreTestConfiguration.ServerVersion;
@@ -277,6 +282,7 @@ private ClusterType MapTopologyToClusterType(string topology)
277282
{
278283
switch (topology)
279284
{
285+
case "load-balanced": throw new SkipException("Topology load-balanced has not been implemented yet.");
280286
case "single": return Clusters.ClusterType.Standalone;
281287
case "replicaset": return Clusters.ClusterType.ReplicaSet;
282288
case "sharded-replicaset":

tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/MonitoringTestRunner.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void ApplyResponse(BsonArray response)
8484

8585
var address = response[0].AsString;
8686
var isMasterDocument = response[1].AsBsonDocument;
87-
JsonDrivenHelper.EnsureAllFieldsAreValid(isMasterDocument, "hosts", "ismaster", "maxWireVersion", "minWireVersion", "ok", "primary", "secondary", "setName", "setVersion");
87+
JsonDrivenHelper.EnsureAllFieldsAreValid(isMasterDocument, "hosts", "isWritablePrimary", OppressiveLanguageConstants.LegacyHelloResponseIsWritablePrimaryFieldName, "maxWireVersion", "minWireVersion", "ok", "primary", "secondary", "setName", "setVersion");
8888

8989
var endPoint = EndPointHelper.Parse(address);
9090
var isMasterResult = new IsMasterResult(isMasterDocument);
@@ -362,6 +362,12 @@ protected override IEnumerable<JsonDrivenTestCase> CreateTestCases(BsonDocument
362362
var name = GetTestCaseName(document, document, 0);
363363
yield return new JsonDrivenTestCase(name, document, document);
364364
}
365+
366+
protected override bool ShouldReadJsonDocument(string path)
367+
{
368+
// load balancer support not yet implemented
369+
return base.ShouldReadJsonDocument(path) && !path.EndsWith("load_balancer.json");
370+
}
365371
}
366372
}
367373
}

tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
using System.IO;
1819
using System.Linq;
1920
using System.Threading;
2021
using FluentAssertions;
@@ -121,7 +122,7 @@ private void ApplyApplicationError(BsonDocument applicationError)
121122
mongoConnectionException.Generation = generation;
122123
}
123124
}
124-
125+
125126
mockConnection.SetupGet(c => c.Generation).Returns(generation);
126127
mockConnection
127128
.SetupGet(c => c.Generation)
@@ -186,7 +187,8 @@ private void ApplyResponse(BsonArray response)
186187
"electionId",
187188
"hidden",
188189
"hosts",
189-
"ismaster",
190+
"isWritablePrimary",
191+
OppressiveLanguageConstants.LegacyHelloResponseIsWritablePrimaryFieldName,
190192
"isreplicaset",
191193
"logicalSessionTimeoutMinutes",
192194
"maxWireVersion",
@@ -529,7 +531,11 @@ private ICluster BuildCluster(BsonDocument definition)
529531
private class TestCaseFactory : JsonDrivenTestCaseFactory
530532
{
531533
// private constants
532-
private const string MonitoringPrefix = "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring.";
534+
private readonly string[] MonitoringPrefixes =
535+
{
536+
"MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring.",
537+
"MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.legacy_hello.monitoring."
538+
};
533539

534540
protected override string PathPrefix => "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.";
535541

@@ -541,7 +547,10 @@ protected override IEnumerable<JsonDrivenTestCase> CreateTestCases(BsonDocument
541547

542548
protected override bool ShouldReadJsonDocument(string path)
543549
{
544-
return base.ShouldReadJsonDocument(path) && !path.StartsWith(MonitoringPrefix);
550+
var loadBalancerTestDirectory = $"{Path.PathSeparator}load-balanced{Path.PathSeparator}";
551+
return base.ShouldReadJsonDocument(path) &&
552+
!MonitoringPrefixes.Any(prefix => path.StartsWith(prefix)) &&
553+
!path.Contains(loadBalancerTestDirectory); // load balancer support not yet implemented
545554
}
546555
}
547556
}

tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public void TestExplainWithFieldsAndCoveredIndex()
5151
if (winningPlan.Contains("shards"))
5252
{
5353
winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument;
54+
// MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper
55+
if (winningPlan.Contains("queryPlan"))
56+
{
57+
winningPlan = winningPlan["queryPlan"].AsBsonDocument;
58+
}
5459
}
5560
var inputStage = winningPlan["inputStage"].AsBsonDocument;
5661
var stage = inputStage["stage"].AsString;

tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public void TestIndexNameHintIsUsedInQuery()
134134
if (winningPlan.Contains("shards"))
135135
{
136136
winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument;
137+
// MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper
138+
if (winningPlan.Contains("queryPlan"))
139+
{
140+
winningPlan = winningPlan["queryPlan"].AsBsonDocument;
141+
}
137142
}
138143
var inputStage = winningPlan["inputStage"].AsBsonDocument;
139144
var stage = inputStage["stage"].AsString;
@@ -221,6 +226,11 @@ public void TestIndexDocumentHintIsUsedInQuery()
221226
if (winningPlan.Contains("shards"))
222227
{
223228
winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument;
229+
// MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper
230+
if (winningPlan.Contains("queryPlan"))
231+
{
232+
winningPlan = winningPlan["queryPlan"].AsBsonDocument;
233+
}
224234
}
225235
var inputStage = winningPlan["inputStage"].AsBsonDocument;
226236
var stage = inputStage["stage"].AsString;

tests/MongoDB.Driver.Tests/ClusterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class ClusterTests
4040
{
4141
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
4242
{
43-
"isMaster",
43+
"hello",
44+
OppressiveLanguageConstants.LegacyHelloCommandName,
4445
"buildInfo",
4546
"getLastError",
4647
"authenticate",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using MongoDB.Bson;
1919
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
2020
using MongoDB.Driver.Core;
21+
using Xunit;
2122

2223
namespace MongoDB.Driver.Tests.JsonDrivenTests
2324
{
@@ -114,6 +115,7 @@ public JsonDrivenTest CreateTest(string receiver, string name)
114115
switch (name)
115116
{
116117
case "listDatabaseNames": return new JsonDrivenListDatabaseNamesTest(_client, _objectMap);
118+
case "listDatabaseObjects": throw new SkipException(".NET/C# driver does not implement a ListDatabaseObjects helper.");
117119
case "listDatabases": return new JsonDrivenListDatabasesTest(_client, _objectMap);
118120
case "watch": return new JsonDrivenClientWatchTest(_client, _objectMap);
119121
default: throw new FormatException($"Invalid method name: \"{name}\".");
@@ -138,6 +140,7 @@ public JsonDrivenTest CreateTest(string receiver, string name)
138140
case "createCollection": return new JsonDrivenCreateCollectionTest(database, _objectMap);
139141
case "dropCollection": return new JsonDrivenDropCollectionTest(database, _objectMap);
140142
case "listCollectionNames": return new JsonDrivenListCollectionNamesTest(database, _objectMap);
143+
case "listCollectionObjects": throw new SkipException(".NET/C# driver does not implement a ListCollectionObjects helper.");
141144
case "listCollections": return new JsonDrivenListCollectionsTest(database, _objectMap);
142145
case "runCommand": return new JsonDrivenRunCommandTest(database, _objectMap);
143146
case "watch": return new JsonDrivenDatabaseWatchTest(database, _objectMap);
@@ -168,6 +171,7 @@ public JsonDrivenTest CreateTest(string receiver, string name)
168171
case "insertMany": return new JsonDrivenInsertManyTest(collection, _objectMap);
169172
case "insertOne": return new JsonDrivenInsertOneTest(collection, _objectMap);
170173
case "listIndexes": return new JsonDrivenListIndexesTest(collection, _objectMap);
174+
case "listIndexNames": throw new SkipException(".NET/C# driver does not implement a ListIndexNames helper.");
171175
case "mapReduce": return new JsonDrivenMapReduceTest(collection, _objectMap);
172176
case "replaceOne": return new JsonDrivenReplaceOneTest(collection, _objectMap);
173177
case "updateMany": return new JsonDrivenUpdateManyTest(collection, _objectMap);

tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class PinnedShardRouterTests
3434
{
3535
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
3636
{
37-
"isMaster",
37+
"hello",
38+
OppressiveLanguageConstants.LegacyHelloCommandName,
3839
"buildInfo",
3940
"getLastError",
4041
"authenticate",

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public abstract class MongoClientJsonDrivenTestRunnerBase
4949
private readonly string _skipReasonKey = "skipReason";
5050
private readonly HashSet<string> _defaultCommandsToNotCapture = new HashSet<string>
5151
{
52-
"isMaster",
52+
"hello",
53+
OppressiveLanguageConstants.LegacyHelloCommandName,
5354
"buildInfo",
5455
"getLastError",
5556
"authenticate",
@@ -329,14 +330,30 @@ protected virtual bool TryConfigureClientOption(MongoClientSettings settings, Bs
329330
settings.ConnectTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32());
330331
break;
331332

333+
case "directConnection":
334+
settings.DirectConnection = option.Value.ToBoolean();
335+
break;
336+
332337
case "heartbeatFrequencyMS":
333338
settings.HeartbeatInterval = TimeSpan.FromMilliseconds(option.Value.ToInt32());
334339
break;
335340

341+
case "maxPoolSize":
342+
settings.MaxConnectionPoolSize = option.Value.ToInt32();
343+
break;
344+
345+
case "minPoolSize":
346+
settings.MinConnectionPoolSize = option.Value.ToInt32();
347+
break;
348+
336349
case "serverSelectionTimeoutMS":
337350
settings.ServerSelectionTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32());
338351
break;
339352

353+
case "socketTimeoutMS":
354+
settings.SocketTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32());
355+
break;
356+
340357
default:
341358
return false;
342359
}

tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using MongoDB.Driver.Core.Bindings;
2626
using MongoDB.Driver.Core.Clusters.ServerSelectors;
2727
using MongoDB.Driver.Core.Events;
28+
using MongoDB.Driver.Core.Misc;
2829
using MongoDB.Driver.Core.TestHelpers;
2930
using MongoDB.Driver.Core.TestHelpers.JsonDrivenTests;
3031
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
@@ -91,7 +92,8 @@ private void Run(BsonDocument shared, BsonDocument test)
9192
}
9293
}
9394

94-
if (test.Contains("expectations") && actualEvents != null)
95+
// expectations == null indicates that expectations should not be asserted.
96+
if (test.Contains("expectations") && !test["expectations"].IsBsonNull && actualEvents != null)
9597
{
9698
var expectedEvents = test["expectations"].AsBsonArray.Cast<BsonDocument>().ToList();
9799
AssertEvents(actualEvents, expectedEvents);
@@ -174,7 +176,8 @@ private EventCapturer CreateEventCapturer()
174176
{
175177
var commandsToNotCapture = new HashSet<string>
176178
{
177-
"isMaster",
179+
"hello",
180+
OppressiveLanguageConstants.LegacyHelloCommandName,
178181
"buildInfo",
179182
"getLastError",
180183
"authenticate",

0 commit comments

Comments
 (0)