From f43cda73f736881ab35482f9c3556583c278c77e Mon Sep 17 00:00:00 2001 From: James Kovacs Date: Thu, 10 Jun 2021 14:40:26 -0600 Subject: [PATCH 1/4] CSHARP-3705: Ignore hello commands during event capture for UnifiedTestRunner. --- .../UnifiedTestOperations/UnifiedEntityMap.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedEntityMap.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedEntityMap.cs index ea7df3b8d2f..4c29df90b2f 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedEntityMap.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedEntityMap.cs @@ -501,7 +501,8 @@ private IGridFSBucket CreateBucket(BsonDocument entity, Dictionary Date: Fri, 11 Jun 2021 14:02:36 -0600 Subject: [PATCH 2/4] CSHARP-3705: Updates to spec testing code to handle hello and ignore tests related to not-yet-implemented load balancer support. --- .../XunitExtensions/RequireServer.cs | 6 ++++++ .../MonitoringTestRunner.cs | 8 +++++++- .../ServerDiscoveryAndMonitoringTestRunner.cs | 12 ++++++++---- tests/MongoDB.Driver.Tests/ClusterTests.cs | 3 ++- .../JsonDrivenTests/JsonDrivenTestFactory.cs | 4 ++++ .../PinnedShardRouterTests.cs | 3 ++- .../MongoClientJsonDrivenTestRunnerBase.cs | 19 ++++++++++++++++++- .../change-streams/ChangeStreamTestRunner.cs | 7 +++++-- .../prose-tests/ClientEncryptionProseTests.cs | 3 ++- .../Specifications/crud/CrudTestRunner.cs | 4 +++- .../RetryableReadsTestRunner.cs | 4 +++- .../prose-tests/CommandConstructionTests.cs | 3 ++- ...overyAndMonitoringIntegrationTestRunner.cs | 1 - .../transactions/TransactionTestRunner.cs | 4 +++- .../UnifiedTestRunner.cs | 5 +++++ 15 files changed, 70 insertions(+), 16 deletions(-) diff --git a/tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs b/tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs index 9d21f6bc403..91181448300 100644 --- a/tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs +++ b/tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs @@ -222,6 +222,11 @@ private bool CanRunOn(ICluster cluster, BsonDocument requirement) { switch (item.Name) { + case "authEnabled": + { + var actualAuthentication = CoreTestConfiguration.ConnectionString.Username != null; + return actualAuthentication == item.Value.AsBoolean; + } case "minServerVersion": { var actualVersion = CoreTestConfiguration.ServerVersion; @@ -277,6 +282,7 @@ private ClusterType MapTopologyToClusterType(string topology) { switch (topology) { + case "load-balanced": throw new SkipException("Topology load-balanced has not been implemented yet."); case "single": return Clusters.ClusterType.Standalone; case "replicaset": return Clusters.ClusterType.ReplicaSet; case "sharded-replicaset": diff --git a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/MonitoringTestRunner.cs b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/MonitoringTestRunner.cs index 0fc8badf233..a71bef15fd2 100644 --- a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/MonitoringTestRunner.cs +++ b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/MonitoringTestRunner.cs @@ -84,7 +84,7 @@ private void ApplyResponse(BsonArray response) var address = response[0].AsString; var isMasterDocument = response[1].AsBsonDocument; - JsonDrivenHelper.EnsureAllFieldsAreValid(isMasterDocument, "hosts", "ismaster", "maxWireVersion", "minWireVersion", "ok", "primary", "secondary", "setName", "setVersion"); + JsonDrivenHelper.EnsureAllFieldsAreValid(isMasterDocument, "hosts", "isWritablePrimary", OppressiveLanguageConstants.LegacyHelloResponseIsWritablePrimaryFieldName, "maxWireVersion", "minWireVersion", "ok", "primary", "secondary", "setName", "setVersion"); var endPoint = EndPointHelper.Parse(address); var isMasterResult = new IsMasterResult(isMasterDocument); @@ -362,6 +362,12 @@ protected override IEnumerable CreateTestCases(BsonDocument var name = GetTestCaseName(document, document, 0); yield return new JsonDrivenTestCase(name, document, document); } + + protected override bool ShouldReadJsonDocument(string path) + { + // load balancer support not yet implemented + return base.ShouldReadJsonDocument(path) && !path.EndsWith("load_balancer.json"); + } } } } diff --git a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs index 5b9bf991ff1..d65aa65bbbf 100644 --- a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs +++ b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs @@ -121,7 +121,7 @@ private void ApplyApplicationError(BsonDocument applicationError) mongoConnectionException.Generation = generation; } } - + mockConnection.SetupGet(c => c.Generation).Returns(generation); mockConnection .SetupGet(c => c.Generation) @@ -186,7 +186,8 @@ private void ApplyResponse(BsonArray response) "electionId", "hidden", "hosts", - "ismaster", + "isWritablePrimary", + OppressiveLanguageConstants.LegacyHelloResponseIsWritablePrimaryFieldName, "isreplicaset", "logicalSessionTimeoutMinutes", "maxWireVersion", @@ -529,7 +530,8 @@ private ICluster BuildCluster(BsonDocument definition) private class TestCaseFactory : JsonDrivenTestCaseFactory { // private constants - private const string MonitoringPrefix = "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring."; + private readonly string[] MonitoringPrefixes = {"MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring.", + "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.legacy_hello.monitoring."}; protected override string PathPrefix => "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests."; @@ -541,7 +543,9 @@ protected override IEnumerable CreateTestCases(BsonDocument protected override bool ShouldReadJsonDocument(string path) { - return base.ShouldReadJsonDocument(path) && !path.StartsWith(MonitoringPrefix); + return base.ShouldReadJsonDocument(path) && + !MonitoringPrefixes.Any(prefix => path.StartsWith(prefix)) && + !path.EndsWith("discover_load_balancer.json"); // load balancer support not yet implemented } } } diff --git a/tests/MongoDB.Driver.Tests/ClusterTests.cs b/tests/MongoDB.Driver.Tests/ClusterTests.cs index 78242ad8af1..dfe70f0ca08 100644 --- a/tests/MongoDB.Driver.Tests/ClusterTests.cs +++ b/tests/MongoDB.Driver.Tests/ClusterTests.cs @@ -40,7 +40,8 @@ public class ClusterTests { private static readonly HashSet __commandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenTestFactory.cs b/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenTestFactory.cs index d0b7ff7b088..4e9a1d24fa2 100644 --- a/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenTestFactory.cs +++ b/tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenTestFactory.cs @@ -18,6 +18,7 @@ using MongoDB.Bson; using MongoDB.Bson.TestHelpers.JsonDrivenTests; using MongoDB.Driver.Core; +using Xunit; namespace MongoDB.Driver.Tests.JsonDrivenTests { @@ -114,6 +115,7 @@ public JsonDrivenTest CreateTest(string receiver, string name) switch (name) { case "listDatabaseNames": return new JsonDrivenListDatabaseNamesTest(_client, _objectMap); + case "listDatabaseObjects": throw new SkipException(".NET/C# driver does not implement a ListDatabaseObjects helper."); case "listDatabases": return new JsonDrivenListDatabasesTest(_client, _objectMap); case "watch": return new JsonDrivenClientWatchTest(_client, _objectMap); default: throw new FormatException($"Invalid method name: \"{name}\"."); @@ -138,6 +140,7 @@ public JsonDrivenTest CreateTest(string receiver, string name) case "createCollection": return new JsonDrivenCreateCollectionTest(database, _objectMap); case "dropCollection": return new JsonDrivenDropCollectionTest(database, _objectMap); case "listCollectionNames": return new JsonDrivenListCollectionNamesTest(database, _objectMap); + case "listCollectionObjects": throw new SkipException(".NET/C# driver does not implement a ListCollectionObjects helper."); case "listCollections": return new JsonDrivenListCollectionsTest(database, _objectMap); case "runCommand": return new JsonDrivenRunCommandTest(database, _objectMap); case "watch": return new JsonDrivenDatabaseWatchTest(database, _objectMap); @@ -168,6 +171,7 @@ public JsonDrivenTest CreateTest(string receiver, string name) case "insertMany": return new JsonDrivenInsertManyTest(collection, _objectMap); case "insertOne": return new JsonDrivenInsertOneTest(collection, _objectMap); case "listIndexes": return new JsonDrivenListIndexesTest(collection, _objectMap); + case "listIndexNames": throw new SkipException(".NET/C# driver does not implement a ListIndexNames helper."); case "mapReduce": return new JsonDrivenMapReduceTest(collection, _objectMap); case "replaceOne": return new JsonDrivenReplaceOneTest(collection, _objectMap); case "updateMany": return new JsonDrivenUpdateManyTest(collection, _objectMap); diff --git a/tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs b/tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs index b1b7954680b..2823d3fe329 100644 --- a/tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs +++ b/tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs @@ -34,7 +34,8 @@ public class PinnedShardRouterTests { private static readonly HashSet __commandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs b/tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs index c938a44443f..91f325dcbb9 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs @@ -49,7 +49,8 @@ public abstract class MongoClientJsonDrivenTestRunnerBase private readonly string _skipReasonKey = "skipReason"; private readonly HashSet _defaultCommandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", @@ -329,14 +330,30 @@ protected virtual bool TryConfigureClientOption(MongoClientSettings settings, Bs settings.ConnectTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; + case "directConnection": + settings.DirectConnection = option.Value.ToBoolean(); + break; + case "heartbeatFrequencyMS": settings.HeartbeatInterval = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; + case "maxPoolSize": + settings.MaxConnectionPoolSize = option.Value.ToInt32(); + break; + + case "minPoolSize": + settings.MinConnectionPoolSize = option.Value.ToInt32(); + break; + case "serverSelectionTimeoutMS": settings.ServerSelectionTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; + case "socketTimeoutMS": + settings.SocketTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32()); + break; + default: return false; } diff --git a/tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs index cd59cc61852..40c8e7e2219 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs @@ -25,6 +25,7 @@ using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters.ServerSelectors; using MongoDB.Driver.Core.Events; +using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers; using MongoDB.Driver.Core.TestHelpers.JsonDrivenTests; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; @@ -91,7 +92,8 @@ private void Run(BsonDocument shared, BsonDocument test) } } - if (test.Contains("expectations") && actualEvents != null) + // expectations == null indicates that expectations should not be asserted. + if (test.Contains("expectations") && !test["expectations"].IsBsonNull && actualEvents != null) { var expectedEvents = test["expectations"].AsBsonArray.Cast().ToList(); AssertEvents(actualEvents, expectedEvents); @@ -174,7 +176,8 @@ private EventCapturer CreateEventCapturer() { var commandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs index 03cd71f58a6..e0b6189ac99 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs @@ -1497,7 +1497,8 @@ private EventCapturer CreateEventCapturer(string commandNameFilter = null) { var defaultCommandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/crud/CrudTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/crud/CrudTestRunner.cs index 19e2fc1c6e4..f2e08c139d9 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/crud/CrudTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/crud/CrudTestRunner.cs @@ -21,6 +21,7 @@ using MongoDB.Bson.TestHelpers.JsonDrivenTests; using MongoDB.Driver.Core; using MongoDB.Driver.Core.Events; +using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.JsonDrivenTests; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.TestHelpers; @@ -34,7 +35,8 @@ public class CrudTestRunner private static readonly HashSet __commandsToNotCapture = new HashSet { "configureFailPoint", - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsTestRunner.cs index 1e1904a2abe..d1be212d19e 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsTestRunner.cs @@ -24,6 +24,7 @@ using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters.ServerSelectors; using MongoDB.Driver.Core.Events; +using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers; using MongoDB.Driver.Core.TestHelpers.JsonDrivenTests; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; @@ -38,7 +39,8 @@ public sealed class RetryableReadsTestRunner #region static private static readonly HashSet __commandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/CommandConstructionTests.cs b/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/CommandConstructionTests.cs index afcfbba94c7..5af9353aeef 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/CommandConstructionTests.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/CommandConstructionTests.cs @@ -435,7 +435,8 @@ private EventCapturer CreateEventCapturer() { var commandsToNotCapture = new HashSet { - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringIntegrationTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringIntegrationTestRunner.cs index c706f6bb0f9..313216de795 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringIntegrationTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringIntegrationTestRunner.cs @@ -18,7 +18,6 @@ using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Bson.TestHelpers.JsonDrivenTests; -using MongoDB.Driver; using MongoDB.Driver.Core; using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters; diff --git a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionTestRunner.cs index a0c657cec04..92068d9d3b1 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionTestRunner.cs @@ -27,6 +27,7 @@ using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Clusters.ServerSelectors; using MongoDB.Driver.Core.Events; +using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.Servers; using MongoDB.Driver.Core.TestHelpers; using MongoDB.Driver.Core.TestHelpers.JsonDrivenTests; @@ -43,7 +44,8 @@ public sealed class TransactionTestRunner : IJsonDrivenTestRunner, IDisposable private static readonly HashSet __commandsToNotCapture = new HashSet { "configureFailPoint", - "isMaster", + "hello", + OppressiveLanguageConstants.LegacyHelloCommandName, "buildInfo", "getLastError", "authenticate", diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs index f566f797e3c..facd790acc8 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs @@ -51,6 +51,11 @@ public UnifiedTestRunner( public void Run(JsonDrivenTestCase testCase) { + if (testCase.Name.Contains("mongos-unpin.json")) + { + throw new SkipException("Load balancer support not yet implemented."); + } + // Top-level fields var schemaVersion = testCase.Shared["schemaVersion"].AsString; // cannot be null var testSetRunOnRequirements = testCase.Shared.GetValue("runOnRequirements", null)?.AsBsonArray; From 444accf98d930f383f9fcf95f363fdb970b82c2d Mon Sep 17 00:00:00 2001 From: James Kovacs Date: Fri, 11 Jun 2021 17:04:42 -0600 Subject: [PATCH 3/4] CSHARP-3705: Updated sharded cluster test to reflect new explain plan output from 5.0 sharded clusters. --- .../MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs | 5 +++++ .../MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs b/tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs index ab03e15d940..693baa53984 100644 --- a/tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs +++ b/tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs @@ -51,6 +51,11 @@ public void TestExplainWithFieldsAndCoveredIndex() if (winningPlan.Contains("shards")) { winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument; + // MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper + if (winningPlan.Contains("queryPlan")) + { + winningPlan = winningPlan["queryPlan"].AsBsonDocument; + } } var inputStage = winningPlan["inputStage"].AsBsonDocument; var stage = inputStage["stage"].AsString; diff --git a/tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs b/tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs index 4aef1d558e8..1148e0b1a03 100644 --- a/tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs +++ b/tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs @@ -134,6 +134,11 @@ public void TestIndexNameHintIsUsedInQuery() if (winningPlan.Contains("shards")) { winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument; + // MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper + if (winningPlan.Contains("queryPlan")) + { + winningPlan = winningPlan["queryPlan"].AsBsonDocument; + } } var inputStage = winningPlan["inputStage"].AsBsonDocument; var stage = inputStage["stage"].AsString; @@ -221,6 +226,11 @@ public void TestIndexDocumentHintIsUsedInQuery() if (winningPlan.Contains("shards")) { winningPlan = winningPlan["shards"][0]["winningPlan"].AsBsonDocument; + // MongoDB 5.0 changes the explain plan output to nest the shard's winningPlan 1 level deeper + if (winningPlan.Contains("queryPlan")) + { + winningPlan = winningPlan["queryPlan"].AsBsonDocument; + } } var inputStage = winningPlan["inputStage"].AsBsonDocument; var stage = inputStage["stage"].AsString; From ef8b66d3c42b1371ce197fa3860573c0f0cd864d Mon Sep 17 00:00:00 2001 From: James Kovacs Date: Mon, 14 Jun 2021 12:06:43 -0600 Subject: [PATCH 4/4] Incorporated PR feedback. --- .../ServerDiscoveryAndMonitoringTestRunner.cs | 11 ++++++++--- .../transactions/TransactionUnifiedTestRunner.cs | 5 +++++ .../UnifiedTestOperations/UnifiedTestRunner.cs | 5 ----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs index d65aa65bbbf..61c3ec7470c 100644 --- a/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs +++ b/tests/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringTestRunner.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using FluentAssertions; @@ -530,8 +531,11 @@ private ICluster BuildCluster(BsonDocument definition) private class TestCaseFactory : JsonDrivenTestCaseFactory { // private constants - private readonly string[] MonitoringPrefixes = {"MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring.", - "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.legacy_hello.monitoring."}; + private readonly string[] MonitoringPrefixes = + { + "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.monitoring.", + "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests.legacy_hello.monitoring." + }; protected override string PathPrefix => "MongoDB.Driver.Core.Tests.Specifications.server_discovery_and_monitoring.tests."; @@ -543,9 +547,10 @@ protected override IEnumerable CreateTestCases(BsonDocument protected override bool ShouldReadJsonDocument(string path) { + var loadBalancerTestDirectory = $"{Path.PathSeparator}load-balanced{Path.PathSeparator}"; return base.ShouldReadJsonDocument(path) && !MonitoringPrefixes.Any(prefix => path.StartsWith(prefix)) && - !path.EndsWith("discover_load_balancer.json"); // load balancer support not yet implemented + !path.Contains(loadBalancerTestDirectory); // load balancer support not yet implemented } } } diff --git a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionUnifiedTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionUnifiedTestRunner.cs index 852ebb67b23..a74945c8bea 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionUnifiedTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionUnifiedTestRunner.cs @@ -27,6 +27,11 @@ public sealed class TransactionUnifiedTestRunner [ClassData(typeof(TestCaseFactory))] public void Run(JsonDrivenTestCase testCase) { + if (testCase.Name.Contains("mongos-unpin.json")) + { + throw new SkipException("Load balancer support not yet implemented."); + } + using (var runner = new UnifiedTestRunner()) { runner.Run(testCase); diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs index facd790acc8..f566f797e3c 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTestRunner.cs @@ -51,11 +51,6 @@ public UnifiedTestRunner( public void Run(JsonDrivenTestCase testCase) { - if (testCase.Name.Contains("mongos-unpin.json")) - { - throw new SkipException("Load balancer support not yet implemented."); - } - // Top-level fields var schemaVersion = testCase.Shared["schemaVersion"].AsString; // cannot be null var testSetRunOnRequirements = testCase.Shared.GetValue("runOnRequirements", null)?.AsBsonArray;