Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ private bool CanRunOn(ICluster cluster, BsonDocument requirement)
{
switch (item.Name)
{
case "authEnabled":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authEnabled is a new field being added with the updated SDAM spec tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's for non-unified format, it would be good if when we add a new logic to both old and new formats, we tried to choose similar keys :)

{
var actualAuthentication = CoreTestConfiguration.ConnectionString.Username != null;
return actualAuthentication == item.Value.AsBoolean;
}
case "minServerVersion":
{
var actualVersion = CoreTestConfiguration.ServerVersion;
Expand Down Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -362,6 +362,12 @@ protected override IEnumerable<JsonDrivenTestCase> 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");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using FluentAssertions;
Expand Down Expand Up @@ -121,7 +122,7 @@ private void ApplyApplicationError(BsonDocument applicationError)
mongoConnectionException.Generation = generation;
}
}

mockConnection.SetupGet(c => c.Generation).Returns(generation);
mockConnection
.SetupGet(c => c.Generation)
Expand Down Expand Up @@ -186,7 +187,8 @@ private void ApplyResponse(BsonArray response)
"electionId",
"hidden",
"hosts",
"ismaster",
"isWritablePrimary",
OppressiveLanguageConstants.LegacyHelloResponseIsWritablePrimaryFieldName,
"isreplicaset",
"logicalSessionTimeoutMinutes",
"maxWireVersion",
Expand Down Expand Up @@ -529,7 +531,11 @@ 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.";

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

protected override bool ShouldReadJsonDocument(string path)
{
return base.ShouldReadJsonDocument(path) && !path.StartsWith(MonitoringPrefix);
var loadBalancerTestDirectory = $"{Path.PathSeparator}load-balanced{Path.PathSeparator}";
return base.ShouldReadJsonDocument(path) &&
!MonitoringPrefixes.Any(prefix => path.StartsWith(prefix)) &&
!path.Contains(loadBalancerTestDirectory); // load balancer support not yet implemented
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/MongoDB.Driver.Legacy.Tests/Jira/CSharp365Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/MongoDB.Driver.Legacy.Tests/Linq/WithIndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/MongoDB.Driver.Tests/ClusterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class ClusterTests
{
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using MongoDB.Bson;
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
using MongoDB.Driver.Core;
using Xunit;

namespace MongoDB.Driver.Tests.JsonDrivenTests
{
Expand Down Expand Up @@ -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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where this option come from? I don't see it in the specs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is coming from the updated retryable reads spec tests, which will be merged after this PR.

case "listDatabases": return new JsonDrivenListDatabasesTest(_client, _objectMap);
case "watch": return new JsonDrivenClientWatchTest(_client, _objectMap);
default: throw new FormatException($"Invalid method name: \"{name}\".");
Expand All @@ -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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above, I don't see this key in the spec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is coming from the updated retryable reads spec tests, which will be merged after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this option looks like this one: https://github.com/mongodb/specifications/blob/master/source/unified-test-format/unified-test-format.rst#listcollections (that I already implemented in load balanced PR), is it different step?

case "listCollections": return new JsonDrivenListCollectionsTest(database, _objectMap);
case "runCommand": return new JsonDrivenRunCommandTest(database, _objectMap);
case "watch": return new JsonDrivenDatabaseWatchTest(database, _objectMap);
Expand Down Expand Up @@ -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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is coming from the updated retryable reads spec tests, which will be merged after this PR.

case "mapReduce": return new JsonDrivenMapReduceTest(collection, _objectMap);
case "replaceOne": return new JsonDrivenReplaceOneTest(collection, _objectMap);
case "updateMany": return new JsonDrivenUpdateManyTest(collection, _objectMap);
Expand Down
3 changes: 2 additions & 1 deletion tests/MongoDB.Driver.Tests/PinnedShardRouterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class PinnedShardRouterTests
{
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public abstract class MongoClientJsonDrivenTestRunnerBase
private readonly string _skipReasonKey = "skipReason";
private readonly HashSet<string> _defaultCommandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BsonDocument>().ToList();
AssertEvents(actualEvents, expectedEvents);
Expand Down Expand Up @@ -174,7 +176,8 @@ private EventCapturer CreateEventCapturer()
{
var commandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,8 @@ private EventCapturer CreateEventCapturer(string commandNameFilter = null)
{
var defaultCommandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +35,8 @@ public class CrudTestRunner
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
{
"configureFailPoint",
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,8 @@ public sealed class RetryableReadsTestRunner
#region static
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ private EventCapturer CreateEventCapturer()
{
var commandsToNotCapture = new HashSet<string>
{
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
using MongoDB.Driver;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we usually don't leave such small changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an unused using. Figured I'd remove it since I was making other edits in the same set of files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't do it because it makes a git history a bit messy (you didn't make any valuable changes in the file but you see this file in the log), but it's minor anyway

using MongoDB.Driver.Core;
using MongoDB.Driver.Core.Bindings;
using MongoDB.Driver.Core.Clusters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +44,8 @@ public sealed class TransactionTestRunner : IJsonDrivenTestRunner, IDisposable
private static readonly HashSet<string> __commandsToNotCapture = new HashSet<string>
{
"configureFailPoint",
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"buildInfo",
"getLastError",
"authenticate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ private IGridFSBucket CreateBucket(BsonDocument entity, Dictionary<string, IMong
"configureFailPoint",
"getLastError",
"getnonce",
"isMaster",
"hello",
OppressiveLanguageConstants.LegacyHelloCommandName,
"saslContinue",
"saslStart"
};
Expand Down