protected void SetupAndRunTest(JsonDrivenTestCase testCase)
        {
            Logger.Debug("Running {0}", testCase.Name);

            CheckServerRequirements(testCase.Shared);
            SetupAndRunTest(testCase.Shared, testCase.Test);
        }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "description", "uri", "valid", "credential");

            MongoCredential mongoCredential = null;
            Exception       parseException  = null;

            try
            {
                var connectionString = (string)definition["uri"];
                mongoCredential = MongoClientSettings.FromConnectionString(connectionString).Credential;
            }
            catch (Exception ex)
            {
                parseException = ex;
            }

            if (parseException == null)
            {
                AssertValid(mongoCredential, definition);
            }
            else
            {
                AssertInvalid(parseException, definition);
            }
        }
Exemple #3
0
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var shared = testCase.Shared;
            var test   = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(
                shared,
                "_path",
                "description",
                "bson_type",  // ignored
                "test_key",   // ignored
                "deprecated", // ignored
                "valid",
                "decodeErrors",
                "parseErrors");

            var testType = test["type"].AsString;

            switch (testType)
            {
            case "valid": RunValidTest(test); break;

            case "decodeErrors": RunDecodeErrorsTest(test); break;

            case "parseErrors": RunParseErrorsTest(test); break;

            default: throw new Exception($"Invalid test type: {testType}.");
            }
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     using (var runner = new UnifiedTestRunner(loggerFactory: LoggerFactory))
     {
         runner.Run(testCase);
     }
 }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "valid", "options", "hosts", "auth", "description", "uri", "warning");

            ConnectionString connectionString = null;
            Exception        parseException   = null;

            try
            {
                connectionString = new ConnectionString((string)definition["uri"]);
            }
            catch (Exception ex)
            {
                parseException = ex;
            }

            if (parseException == null)
            {
                AssertValid(connectionString, definition);
            }
            else
            {
                AssertInvalid(parseException, definition);
            }
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     using (var runner = new UnifiedTestRunner())
     {
         runner.Run(testCase);
     }
 }
        public void Run(JsonDrivenTestCase testCase)
        {
#if DEBUG
            RequirePlatform
            .Check()
            .SkipWhen(SupportedOperatingSystem.Linux)
            .SkipWhen(SupportedOperatingSystem.MacOS);
            // Make sure that LB is started. "nginx" is a LB we use for windows testing
            RequireEnvironment.Check().ProcessStarted("nginx");
            Environment.SetEnvironmentVariable("MONGODB_URI", "mongodb://localhost:17017?loadBalanced=true");
            Environment.SetEnvironmentVariable("MONGODB_URI_WITH_MULTIPLE_MONGOSES", "mongodb://localhost:17018?loadBalanced=true");
            RequireServer
            .Check()
            .LoadBalancing(enabled: true, ignorePreviousSetup: true)
            .Authentication(authentication: false); // auth server requires credentials in connection string
#else
            RequireEnvironment                      // these env variables are used only on the scripting side
            .Check()
            .EnvironmentVariable("SINGLE_MONGOS_LB_URI")
            .EnvironmentVariable("MULTI_MONGOS_LB_URI");
            // EG currently supports LB only for Ubuntu
            RequirePlatform
            .Check()
            .SkipWhen(SupportedOperatingSystem.Windows)
            .SkipWhen(SupportedOperatingSystem.MacOS);
#endif

            using (var runner = new UnifiedTestRunner())
            {
                runner.Run(testCase);
            }
        }
Exemple #8
0
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var testDefinition     = testCase.Test;
            var testData           = BsonSerializer.Deserialize <TestData>(testDefinition);
            var clusterDescription = ServerSelectionTestHelper.BuildClusterDescription(testData.topology_description);

            using var cluster = CreateAndSetupCluster(clusterDescription, testData.mocked_topology_state);
            var readPreferenceSelector = new ReadPreferenceServerSelector(ReadPreference.Nearest);

            var selectionHistogram = testData.outcome.expected_frequencies.Keys
                                     .ToDictionary(s => clusterDescription.Servers.Single(d => d.EndPoint.ToString().EndsWith(s)).ServerId, s => 0);
            var selectionFrequenciesExpected = testData.outcome.expected_frequencies.
                                               ToDictionary(s => clusterDescription.Servers.Single(d => d.EndPoint.ToString().EndsWith(s.Key)).ServerId, s => s.Value);

            for (int i = 0; i < testData.iterations; i++)
            {
                var selectedServer = testData.async
                    ? cluster.SelectServerAsync(readPreferenceSelector, default).GetAwaiter().GetResult()
                    : cluster.SelectServer(readPreferenceSelector, default);

                selectionHistogram[selectedServer.ServerId]++;
            }

            foreach (var pair in selectionHistogram)
            {
                var expectedFrequency = selectionFrequenciesExpected[pair.Key];
                var actualFrequency   = pair.Value / (double)testData.iterations;

                actualFrequency.Should().BeInRange(expectedFrequency - testData.outcome.tolerance, expectedFrequency + testData.outcome.tolerance);
            }
        }
Exemple #9
0
 public void Run(JsonDrivenTestCase testCase)
 {
     using (var runner = new UnifiedTestRunner())
     {
         var exception = Record.Exception(() => runner.Run(testCase));
         exception.Should().NotBeNull();
     }
 }
        public void Run(JsonDrivenTestCase testCase)
        {
            RequirePlatform
            .Check()
            .SkipWhen(SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard15)
            .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard20);     // gcp is supported starting from netstandard2.1

            SetupAndRunTest(testCase);
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     Run(schemaVersion: testCase.Shared["schemaVersion"].AsString,
         testSetRunOnRequirements: testCase.Shared.GetValue("runOnRequirements", null)?.AsBsonArray,
         testRunOnRequirements: testCase.Test.GetValue("runOnRequirements", null)?.AsBsonArray,
         entities: testCase.Shared.GetValue("createEntities", null)?.AsBsonArray,
         initialData: testCase.Shared.GetValue("initialData", null)?.AsBsonArray,
         test: testCase.Test);
 }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "description", "_path", "phases", "uri");

            _cluster = BuildCluster(definition);
            _cluster.Initialize();

            var phases = definition["phases"].AsBsonArray;

            foreach (BsonDocument phase in phases)
            {
                ApplyPhase(phase);
            }
        }
        public void Run(JsonDrivenTestCase testCase)
        {
            // Top-level fields
            var schemaVersion            = testCase.Shared["schemaVersion"].AsString; // cannot be null
            var testSetRunOnRequirements = testCase.Shared.GetValue("runOnRequirements", null)?.AsBsonArray;
            var entities    = testCase.Shared.GetValue("createEntities", null)?.AsBsonArray;
            var initialData = testCase.Shared.GetValue("initialData", null)?.AsBsonArray;
            // Test fields
            var runOnRequirements = testCase.Test.GetValue("runOnRequirements", null)?.AsBsonArray;
            var skipReason        = testCase.Test.GetValue("skipReason", null)?.AsString;
            var operations        = testCase.Test["operations"].AsBsonArray; // cannot be null
            var expectEvents      = testCase.Test.GetValue("expectEvents", null)?.AsBsonArray;
            var outcome           = testCase.Test.GetValue("outcome", null)?.AsBsonArray;
            var async             = testCase.Test["async"].AsBoolean; // cannot be null

            Run(schemaVersion, testSetRunOnRequirements, entities, initialData, runOnRequirements, skipReason, operations, expectEvents, outcome, async);
        }
        public void Run(JsonDrivenTestCase testCase)
        {
            if (testCase.Name.Contains("awsTemporary"))
            {
                // This test requires setting of some temporary environment variables that can be set by mongo orchestration or manually.
                // Add this environment variable on your local machine only together with FLE_AWS_TEMP_* variables (note: they will be expired in 12 hours)
                RequireEnvironment.Check().EnvironmentVariable("FLE_AWS_TEMPORARY_CREDS_ENABLED");
            }

            RequirePlatform
            .Check()
            .SkipWhen(SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard15)
            .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.Linux, SupportedTargetFramework.NetStandard20)     // gcp is supported starting from netstandard2.1
            .SkipWhen(SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard15)
            .SkipWhen(() => testCase.Name.Contains("gcpKMS.json"), SupportedOperatingSystem.MacOS, SupportedTargetFramework.NetStandard20);    // gcp is supported starting from netstandard2.1

            SetupAndRunTest(testCase);
        }
        public void Run(JsonDrivenTestCase testCase)
        {
            if (CoreTestConfiguration.Cluster.Description.Type == ClusterType.Sharded)
            {
                RequireServer.Check().Supports(Feature.ShardedTransactions);
            }
            else
            {
                RequireServer.Check().Supports(Feature.Transactions).ClusterType(ClusterType.ReplicaSet);
            }

            if (testCase.Test.Contains("skipReason"))
            {
                throw new SkipException($"skipReason: {testCase.Test["skipReason"].AsString}");
            }

            Run(testCase.Shared, testCase.Test);
        }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "_path", "in_latency_window", "operation", "read_preference", "suitable_servers", "topology_description", "heartbeatFrequencyMS", "error");

            var error              = definition.GetValue("error", false).ToBoolean();
            var heartbeatInterval  = TimeSpan.FromMilliseconds(definition.GetValue("heartbeatFrequencyMS", 10000).ToInt64());
            var clusterDescription = ServerSelectionTestHelper.BuildClusterDescription((BsonDocument)definition["topology_description"], heartbeatInterval);

            IServerSelector selector;

            if (definition.GetValue("operation", "read").AsString == "write")
            {
                selector = WritableServerSelector.Instance;
            }
            else
            {
                ReadPreference readPreference;
                try
                {
                    readPreference = BuildReadPreference(definition["read_preference"].AsBsonDocument);
                }
                catch
                {
                    if (error)
                    {
                        return;
                    }
                    throw;
                }

                selector = new ReadPreferenceServerSelector(readPreference);
            }

            if (error)
            {
                RunErrorTest(clusterDescription, selector);
            }
            else
            {
                RunNonErrorTest(definition, clusterDescription, selector, heartbeatInterval);
            }
        }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var test = testCase.Test;

            CheckServerRequirements(test);

            var connectionMap = new ConcurrentDictionary <string, IConnection>();
            var eventCapturer = new EventCapturer();
            var tasks         = new ConcurrentDictionary <string, Task>();

            JsonDrivenHelper.EnsureAllFieldsAreValid(test, Schema.AllFields);
            var isUnit = EnsureStyle(test) == Schema.Styles.unit;

            var(connectionPool, failPoint, cluster, eventsFilter) = SetupConnectionData(test, eventCapturer, isUnit);
            using var disposableBundle = new DisposableBundle(failPoint, connectionPool, cluster);

            ResetConnectionId();

            var       operations = testCase.Test.GetValue(Schema.operations).AsBsonArray;
            var       async      = testCase.Test.GetValue(Schema.async).ToBoolean();
            Exception exception  = null;

            foreach (var operation in operations.Cast <BsonDocument>())
            {
                ExecuteOperation(
                    operation,
                    eventCapturer,
                    connectionMap,
                    tasks,
                    connectionPool,
                    async,
                    out exception);

                if (exception != null)
                {
                    break;
                }
            }
#if WINDOWS
            AssertError(test, exception);
            AssertEvents(test, eventCapturer, eventsFilter);
#endif
        }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "description", "valid", "readConcern", "readConcernDocument", "isServerDefault", "writeConcern", "writeConcernDocument", "isAcknowledged");

            BsonValue readConcernValue;

            if (definition.TryGetValue("readConcern", out readConcernValue))
            {
                ValidateReadConcern(definition);
            }

            BsonValue writeConcernValue;

            if (definition.TryGetValue("writeConcern", out writeConcernValue))
            {
                ValidateWriteConcern(definition);
            }
        }
Exemple #20
0
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var connectionMap = new ConcurrentDictionary <string, IConnection>();
            var eventCapturer = new EventCapturer();
            var tasks         = new ConcurrentDictionary <string, Task>();

            var test = testCase.Test;

            JsonDrivenHelper.EnsureAllFieldsAreValid(test, "_path", "version", "style", "description", "poolOptions", "operations", "error", "events", "ignore", "async");
            EnsureAvailableStyle(test);
            ResetConnectionId();

            var connectionPool = SetupConnectionPool(test, eventCapturer);

            connectionPool.Initialize();

            var       operations = testCase.Test.GetValue("operations").AsBsonArray;
            var       async      = testCase.Test.GetValue("async").ToBoolean();
            Exception exception  = null;

            foreach (var operation in operations.Cast <BsonDocument>())
            {
                ExecuteOperation(
                    operation,
                    eventCapturer,
                    connectionMap,
                    tasks,
                    connectionPool,
                    async,
                    out exception);

                if (exception != null)
                {
                    break;
                }
            }
#if WINDOWS
            AssertError(test, exception);
            AssertEvents(test, eventCapturer);
#endif
        }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;
            ConnectionString connectionString = null;
            Exception        parseException   = null;

            try
            {
                connectionString = new ConnectionString((string)definition["uri"]);
            }
            catch (Exception ex)
            {
                parseException = ex;
            }

            if (parseException == null)
            {
                AssertValid(connectionString, definition);
            }
            else
            {
                AssertInvalid(parseException, definition);
            }
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     SetupAndRunTest(testCase);
 }
        public void RunTestDefinition(JsonDrivenTestCase testCase)
        {
            var definition = testCase.Test;

            BsonValue bsonValue;

            if (definition.TryGetValue("ignore_if_server_version_greater_than", out bsonValue))
            {
                var serverVersion    = GetServerVersion();
                var maxServerVersion = SemanticVersion.Parse(bsonValue.AsString);
                if (serverVersion > maxServerVersion)
                {
                    throw new SkipException($"Test ignored because server version {serverVersion} is greater than max server version {maxServerVersion}.");
                }
            }
            if (definition.TryGetValue("ignore_if_server_version_less_than", out bsonValue))
            {
                var serverVersion    = GetServerVersion();
                var minServerVersion = SemanticVersion.Parse(bsonValue.AsString);
                if (serverVersion < minServerVersion)
                {
                    throw new SkipException($"Test ignored because server version {serverVersion} is less than min server version {minServerVersion}.");
                }
            }

            // TODO: re-enable these tests once a decision has been made about how to deal with unexpected fields in the server response (see: CSHARP-2444)
            if (CoreTestConfiguration.ServerVersion >= new SemanticVersion(4, 1, 5, ""))
            {
                switch (definition["description"].AsString)
                {
                case "A successful insert one command with write errors":
                case "A successful insert many command with write errors":
                    throw new SkipException("Test ignored because of CSHARP-2444");
                }
            }

            var data           = testCase.Shared["data"].AsBsonArray.Cast <BsonDocument>().ToList();
            var databaseName   = testCase.Shared["database_name"].AsString;
            var collectionName = testCase.Shared["collection_name"].AsString;

            var operation  = (BsonDocument)definition["operation"];
            var database   = __client.GetDatabase(databaseName);
            var collection = database.GetCollection <BsonDocument>(collectionName);

            database.DropCollection(collection.CollectionNamespace.CollectionName);
            collection.InsertMany(data);

            __capturedEvents.Clear();
            try
            {
                ExecuteOperation(database, collectionName, operation, definition["async"].AsBoolean);
            }
            catch (NotImplementedException)
            {
                throw;
            }
            catch (Exception)
            {
                // catch everything...
            }

            var expectations = (BsonArray)definition["expectations"];

            if (!SpinWait.SpinUntil(() => __capturedEvents.Count == expectations.Count, TimeSpan.FromSeconds(5)))
            {
                throw new Exception($"Expected {expectations.Count} events but only {__capturedEvents.Count} events were captured.");
            }

            long?operationId = null;

            foreach (BsonDocument expected in expectations)
            {
                if (expected.Contains("command_started_event"))
                {
                    var actual = (CommandStartedEvent)__capturedEvents.Next();
                    if (!operationId.HasValue)
                    {
                        operationId = actual.OperationId;
                    }
                    actual.OperationId.Should().Be(operationId);
                    VerifyCommandStartedEvent(actual, (BsonDocument)expected["command_started_event"], databaseName, collectionName);
                }
                else if (expected.Contains("command_succeeded_event"))
                {
                    var actual = (CommandSucceededEvent)__capturedEvents.Next();
                    actual.OperationId.Should().Be(operationId);
                    VerifyCommandSucceededEvent(actual, (BsonDocument)expected["command_succeeded_event"], databaseName, collectionName);
                }
                else if (expected.Contains("command_failed_event"))
                {
                    var actual = (CommandFailedEvent)__capturedEvents.Next();
                    actual.OperationId.Should().Be(operationId);
                    VerifyCommandFailedEvent(actual, (BsonDocument)expected["command_failed_event"], databaseName, collectionName);
                }
                else
                {
                    Assert.True(false, "Unknown event type.");
                }
            }
        }
Exemple #24
0
 protected void SetupAndRunTest(JsonDrivenTestCase testCase)
 {
     CheckServerRequirements(testCase.Shared);
     SetupAndRunTest(testCase.Shared, testCase.Test);
 }
        public void Run(JsonDrivenTestCase testCase)
        {
            RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");

            SetupAndRunTest(testCase);
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     Run(testCase.Shared, testCase.Test);
 }
        public void Run(JsonDrivenTestCase testCase)
        {
            var exception = Record.Exception(() => _unifiedTestFormatTestRunner.Run(testCase));

            exception.Should().NotBeNull();
        }
 public void Run(JsonDrivenTestCase testCase)
 {
     RequireServer.Check().Supports(Feature.Transactions).ClusterType(ClusterType.ReplicaSet);
     Run(testCase.Shared, testCase.Test);
 }