From 9115f8216eec1f5eb9518c1e95df8eeaefc73f88 Mon Sep 17 00:00:00 2001 From: DmitryLukyanov Date: Fri, 1 Oct 2021 18:05:16 +0300 Subject: [PATCH] CSHARP-3790: Remove modifiers option from command monitoring spec test. --- .../CommandMonitoringTestRunner.cs | 16 +++ .../command-monitoring/FindTest.cs | 21 ++++ .../tests/legacy/README.rst | 101 ++++++++++++++---- .../tests/legacy/command.json | 6 +- .../tests/legacy/deleteMany.json | 4 +- .../tests/legacy/deleteOne.json | 4 +- .../command-monitoring/tests/legacy/find.json | 96 +++++++++++------ .../command-monitoring/tests/legacy/find.yml | 52 ++++----- .../tests/legacy/insertOne.json | 4 +- .../valid-pass/poc-command-monitoring.json | 3 +- .../valid-pass/poc-command-monitoring.yml | 3 +- 11 files changed, 218 insertions(+), 92 deletions(-) diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/CommandMonitoringTestRunner.cs b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/CommandMonitoringTestRunner.cs index b903ea731e3..a5dccaf96be 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/CommandMonitoringTestRunner.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/CommandMonitoringTestRunner.cs @@ -103,6 +103,11 @@ public void RunTestDefinition(JsonDrivenTestCase testCase) { var definition = testCase.Test; + if (CoreTestConfiguration.ServerVersion < new SemanticVersion(3, 2, 0)) + { + throw new SkipException("Supporting of these servers are going to be removed soon, so skip them."); + } + BsonValue bsonValue; if (definition.TryGetValue("ignore_if_server_version_greater_than", out bsonValue)) { @@ -122,6 +127,17 @@ public void RunTestDefinition(JsonDrivenTestCase testCase) throw new SkipException($"Test ignored because server version {serverVersion} is less than min server version {minServerVersion}."); } } + if (definition.TryGetValue("ignore_if_topology_type", out bsonValue)) + { + var currentTopology = CoreTestConfiguration.Cluster.Description.Type.ToString().ToLower(); + foreach (var topologyToIgnore in bsonValue.AsBsonArray) + { + if (topologyToIgnore.ToString().ToLower() == currentTopology.ToString().ToLower()) + { + throw new SkipException($"Test ignored because server topology {bsonValue} is not supported."); + } + } + } // 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, "")) diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/FindTest.cs b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/FindTest.cs index 8b720ebe931..a51b9f30447 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/FindTest.cs +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/FindTest.cs @@ -41,6 +41,9 @@ protected override bool TrySetArgument(string name, BsonValue value) { switch (name) { + case "comment": + _options.Comment = value.AsString; + return true; case "filter": _filter = (BsonDocument)value; return true; @@ -61,6 +64,24 @@ protected override bool TrySetArgument(string name, BsonValue value) _options.Modifiers = (BsonDocument)value; #pragma warning restore 618 return true; + case "hint": + _options.Hint = value; + return true; + case "max": + _options.Max = value.ToBsonDocument(); + return true; + case "min": + _options.Min = value.ToBsonDocument(); + return true; + case "maxTimeMS": + _options.MaxTime = TimeSpan.FromMilliseconds(value.ToInt32()); + return true; + case "returnKey": + _options.ReturnKey = value.ToBoolean(); + return true; + case "showRecordId": + _options.ShowRecordId = value.ToBoolean(); + return true; } return false; diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/README.rst b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/README.rst index a2f407827ec..5700409cf32 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/README.rst +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/README.rst @@ -12,12 +12,21 @@ Command Monitoring Testing ======= +Tests in ``unified`` are implemented in the `Unified Test Format <../../unified-test-format/unified-test-format.rst>`__ and require +schema version 1.0. Tests in ``legacy`` should be run as described below. + Tests are provided in YML and JSON format to assert proper upconversion of commands. +Database and Collection Names +----------------------------- + +The collection under test is specified in each test file with the fields +``database_name`` and ``collection_name``. + Data ---- -The {{data}} at the beginning of each test file is the data that should exist in the +The ``data`` at the beginning of each test file is the data that should exist in the collection under test before each test run. Expectations @@ -26,21 +35,21 @@ Expectations Fake Placeholder Values ``````````````````````` -When an attribute in an expectation contains the value {{"42"}}, {{42}} or {{""}}, this is a fake +When an attribute in an expectation contains the value ``"42"``, ``42`` or ``""``, this is a fake placeholder value indicating that a special case MUST be tested that could not be expressed in a YAML or JSON test. These cases are as follows: Cursor Matching ^^^^^^^^^^^^^^^ -When encountering a {{cursor}} or {{getMore}} value of {{"42"}} in a test, the driver MUST assert +When encountering a ``cursor`` or ``getMore`` value of ``"42"`` in a test, the driver MUST assert that the values are equal to each other and greater than zero. Errors ^^^^^^ -For write errors, {{code}} values of {{42}} MUST assert that the value is present and -greater than zero. {{errmsg}} values of {{""}} MUST assert that the value is not empty +For write errors, ``code`` values of ``42`` MUST assert that the value is present and +greater than zero. ``errmsg`` values of ``""`` MUST assert that the value is not empty (a string of length greater than 1). OK Values @@ -56,21 +65,67 @@ Additional Values The expected events provide the minimum data that is required and can be tested. It is possible for more values to be present in the events, such as extra data provided when using sharded clusters or ``nModified`` field in updates. The driver MUST assert the -expected data is present and also MUST allow for additional data to be present as well. - -Ignoring Tests Based On Server Version -`````````````````````````````````````` - -Due to variations in server behaviour, some tests may not be valid on a specific range -of server versions and MUST NOT be run. These tests are indicated with the fields -{{ignore_if_server_version_greater_than}} and {{ignore_if_server_version_less_than}} which -are optionally provided at the description level of the test. When determining if the test -must be run or not, use only the minor server version. - -Example: - -If {{ignore_if_server_version_greater_than}} is {{3.0}}, then the tests MUST NOT run on -{{3.1}} and higher, but MUST run on {{3.0.3}}. - -Tests which do not have either one of these fields MUST run on all supported server -versions. +expected data is present and also MUST allow for additional data to be present as well +at the top level of the command document or reply document. + +For example, say the client sends a causally-consistent "distinct" command with +readConcern level "majority", like:: + + { + "distinct": "collection", + "key": "key", + "readConcern":{ + "afterClusterTime": {"$timestamp":{"t":1522336030,"i":1}}, + "level":"majority" + }, + "$clusterTime": { + "clusterTime": { "$timestamp": { "i": 1, "t": 1522335530 } }, + "signature": { + "hash": { "$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type": "00" }, + "keyId": { "$numberLong": "0" } + } + }, + "lsid": { + "id": { "$binary": "RaigP3oASqu+galPvRAfcg==", "$type": "04" } + } + } + +Then it would pass a command-started event like the following YAML, because the +fields not mentioned in the YAML are ignored:: + + command: + distinct: collection + key: key + +However, if there are fields in command subdocuments that are not mentioned in +the YAML, then the command does *not* pass the test:: + + command: + distinct: collection + key: key + # Fails because the expected readConcern has no "afterClusterTime". + readConcern: + level: majority + +Ignoring Tests Based On Server Version or Topology Type +``````````````````````````````````````````````````````` + +Due to variations in server behavior, some tests may not be valid and MUST NOT be run on +certain server versions or topology types. These tests are indicated with any of the +following fields, which will be optionally provided at the ``description`` level of each +test: + +- ``ignore_if_server_version_greater_than`` (optional): If specified, the test MUST be + skipped if the minor version of the server is greater than this minor version. The + server's patch version MUST NOT be considered. For example, a value of ``3.0`` implies + that the test can run on server version ``3.0.15`` but not ``3.1.0``. + +- ``ignore_if_server_version_less_than`` (optional): If specified, the test MUST be + skipped if the minor version of the server is less than this minor version. The + server's patch version MUST NOT be considered. For example, a value of ``3.2`` implies + that the test can run on server version ``3.2.0`` but not ``3.0.15``. + +- ``ignore_if_topology_type`` (optional): An array of server topologies for which the test + MUST be skipped. Valid topologies are "single", "replicaset", and "sharded". + +Tests that have none of these fields MUST be run on all supported server versions. diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/command.json b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/command.json index 621d18f05dd..7e1e347be07 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/command.json +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/command.json @@ -34,7 +34,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 1 }, "command_name": "count" @@ -101,13 +101,13 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 1 }, "command_name": "count" } } ] - }, + } ] } diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteMany.json b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteMany.json index 11c48423e7b..7cd396806cc 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteMany.json +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteMany.json @@ -52,7 +52,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 2 }, "command_name": "delete" @@ -96,7 +96,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 0, "writeErrors": [ { diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteOne.json b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteOne.json index 22d40122eec..0971dfcf2cd 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteOne.json +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/deleteOne.json @@ -52,7 +52,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 1 }, "command_name": "delete" @@ -96,7 +96,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 0, "writeErrors": [ { diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.json b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.json index 736dc370f6f..e2bb95306fc 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.json +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.json @@ -86,22 +86,22 @@ "sort": { "_id": 1 }, - "skip": 2, - "modifiers": { - "$comment": "test", - "$hint": { - "_id": 1 - }, - "$max": { - "_id": 6 - }, - "$maxTimeMS": 6000, - "$min": { - "_id": 0 - }, - "$returnKey": false, - "$showDiskLoc": false, - } + "skip": { + "$numberLong": "2" + }, + "comment": "test", + "hint": { + "_id": 1 + }, + "max": { + "_id": 6 + }, + "maxTimeMS": 6000, + "min": { + "_id": 0 + }, + "returnKey": false, + "showRecordId": false } }, "expectations": [ @@ -117,7 +117,9 @@ "sort": { "_id": 1 }, - "skip": 2, + "skip": { + "$numberLong": "2" + }, "comment": "test", "hint": { "_id": 1 @@ -130,7 +132,7 @@ "_id": 0 }, "returnKey": false, - "showRecordId": false, + "showRecordId": false }, "command_name": "find", "database_name": "command-monitoring-tests" @@ -175,7 +177,9 @@ "sort": { "_id": 1 }, - "batchSize": 3 + "batchSize": { + "$numberLong": "3" + } } }, "expectations": [ @@ -191,7 +195,9 @@ "sort": { "_id": 1 }, - "batchSize": 3 + "batchSize": { + "$numberLong": "3" + } }, "command_name": "find", "database_name": "command-monitoring-tests" @@ -232,7 +238,9 @@ "$numberLong": "42" }, "collection": "test", - "batchSize": 3 + "batchSize": { + "$numberLong": "3" + } }, "command_name": "getMore", "database_name": "command-monitoring-tests" @@ -278,8 +286,12 @@ "sort": { "_id": 1 }, - "batchSize": 3, - "limit": 4 + "batchSize": { + "$numberLong": "3" + }, + "limit": { + "$numberLong": "4" + } } }, "expectations": [ @@ -295,8 +307,12 @@ "sort": { "_id": 1 }, - "batchSize": 3, - "limit": 4 + "batchSize": { + "$numberLong": "3" + }, + "limit": { + "$numberLong": "4" + } }, "command_name": "find", "database_name": "command-monitoring-tests" @@ -337,7 +353,9 @@ "$numberLong": "42" }, "collection": "test", - "batchSize": 1 + "batchSize": { + "$numberLong": "1" + } }, "command_name": "getMore", "database_name": "command-monitoring-tests" @@ -393,8 +411,12 @@ ] }, { - "description": "A successful find event with a getmore and the server kills the cursor", + "description": "A successful find event with a getmore and the server kills the cursor (<= 4.4)", "ignore_if_server_version_less_than": "3.1", + "ignore_if_server_version_greater_than": "4.4", + "ignore_if_topology_type": [ + "sharded" + ], "operation": { "name": "find", "arguments": { @@ -406,8 +428,12 @@ "sort": { "_id": 1 }, - "batchSize": 3, - "limit": 4 + "batchSize": { + "$numberLong": "3" + }, + "limit": { + "$numberLong": "4" + } } }, "expectations": [ @@ -423,8 +449,12 @@ "sort": { "_id": 1 }, - "batchSize": 3, - "limit": 4 + "batchSize": { + "$numberLong": "3" + }, + "limit": { + "$numberLong": "4" + } }, "command_name": "find", "database_name": "command-monitoring-tests" @@ -465,7 +495,9 @@ "$numberLong": "42" }, "collection": "test", - "batchSize": 1 + "batchSize": { + "$numberLong": "1" + } }, "command_name": "getMore", "database_name": "command-monitoring-tests" diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.yml b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.yml index a673d48702b..8b507283f96 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.yml +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/find.yml @@ -42,16 +42,14 @@ tests: arguments: filter: { _id: { $gt: 1 } } sort: { _id: 1 } - skip: 2 - modifiers: - $comment: "test" - $hint: { _id: 1 } - $max: { _id: 6 } - $maxScan: 5000 - $maxTimeMS: 6000 - $min: { _id: 0 } - $returnKey: false - $showDiskLoc: false + skip: {"$numberLong": "2"} + comment: "test" + hint: { _id: 1 } + max: { _id: 6 } + maxTimeMS: 6000 + min: { _id: 0 } + returnKey: false + showRecordId: false expectations: - command_started_event: @@ -59,11 +57,10 @@ tests: find: *collection_name filter: { _id: { $gt: 1 } } sort: { _id: 1 } - skip: 2 + skip: {"$numberLong": "2"} comment: "test" hint: { _id: 1 } max: { _id: 6 } - maxScan: 5000 maxTimeMS: 6000 min: { _id: 0 } returnKey: false @@ -88,7 +85,7 @@ tests: arguments: filter: { _id: { $gte: 1 }} sort: { _id: 1 } - batchSize: 3 + batchSize: {"$numberLong": "3"} expectations: - command_started_event: @@ -96,7 +93,7 @@ tests: find: *collection_name filter: { _id: { $gte : 1 }} sort: { _id: 1 } - batchSize: 3 + batchSize: {"$numberLong": "3"} command_name: "find" database_name: *database_name - @@ -116,7 +113,7 @@ tests: command: getMore: { $numberLong: "42" } collection: *collection_name - batchSize: 3 + batchSize: {"$numberLong": "3"} command_name: "getMore" database_name: *database_name - @@ -138,8 +135,8 @@ tests: arguments: filter: { _id: { $gte: 1 }} sort: { _id: 1 } - batchSize: 3 - limit: 4 + batchSize: {"$numberLong": "3"} + limit: {"$numberLong": "4"} expectations: - command_started_event: @@ -147,8 +144,8 @@ tests: find: *collection_name filter: { _id: { $gte : 1 }} sort: { _id: 1 } - batchSize: 3 - limit: 4 + batchSize: {"$numberLong": "3"} + limit: {"$numberLong": "4"} command_name: "find" database_name: *database_name - @@ -168,7 +165,7 @@ tests: command: getMore: { $numberLong: "42" } collection: *collection_name - batchSize: 1 + batchSize: { $numberLong: "1" } command_name: "getMore" database_name: *database_name - @@ -197,15 +194,18 @@ tests: - { $numberLong: "42" } command_name: "killCursors" - - description: "A successful find event with a getmore and the server kills the cursor" + description: "A successful find event with a getmore and the server kills the cursor (<= 4.4)" ignore_if_server_version_less_than: "3.1" + ignore_if_server_version_greater_than: "4.4" + ignore_if_topology_type: + - "sharded" operation: name: "find" arguments: filter: { _id: { $gte: 1 }} sort: { _id: 1 } - batchSize: 3 - limit: 4 + batchSize: {"$numberLong": "3"} + limit: {"$numberLong": "4"} expectations: - command_started_event: @@ -213,8 +213,8 @@ tests: find: *collection_name filter: { _id: { $gte : 1 }} sort: { _id: 1 } - batchSize: 3 - limit: 4 + batchSize: {"$numberLong": "3"} + limit: {"$numberLong": "4"} command_name: "find" database_name: *database_name - @@ -234,7 +234,7 @@ tests: command: getMore: { $numberLong: "42" } collection: *collection_name - batchSize: 3 + batchSize: { $numberLong: "1" } command_name: "getMore" database_name: *database_name - diff --git a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/insertOne.json b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/insertOne.json index f202076a439..877bca1a615 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/insertOne.json +++ b/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/tests/legacy/insertOne.json @@ -39,7 +39,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 1 }, "command_name": "insert" @@ -78,7 +78,7 @@ { "command_succeeded_event": { "reply": { - "ok": 1.0, + "ok": 1, "n": 0, "writeErrors": [ { diff --git a/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.json b/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.json index 499396e0baa..fe0a5ae9913 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.json +++ b/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.json @@ -57,10 +57,11 @@ ], "tests": [ { - "description": "A successful find event with a getmore and the server kills the cursor", + "description": "A successful find event with a getmore and the server kills the cursor (<= 4.4)", "runOnRequirements": [ { "minServerVersion": "3.1", + "maxServerVersion": "4.4.99", "topologies": [ "single", "replicaset" diff --git a/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.yml b/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.yml index 19a282327c4..6d5e4373494 100644 --- a/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.yml +++ b/tests/MongoDB.Driver.Tests/Specifications/unified-test-format/tests/valid-pass/poc-command-monitoring.yml @@ -29,9 +29,10 @@ initialData: - { _id: 5, x: 55 } tests: - - description: "A successful find event with a getmore and the server kills the cursor" + - description: "A successful find event with a getmore and the server kills the cursor (<= 4.4)" runOnRequirements: - minServerVersion: "3.1" + maxServerVersion: "4.4.99" topologies: [ single, replicaset ] operations: - name: find