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 @@ -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))
{
Expand All @@ -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, ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 1
},
"command_name": "count"
Expand Down Expand Up @@ -101,13 +101,13 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 1
},
"command_name": "count"
}
}
]
},
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 2
},
"command_name": "delete"
Expand Down Expand Up @@ -96,7 +96,7 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 0,
"writeErrors": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 1
},
"command_name": "delete"
Expand Down Expand Up @@ -96,7 +96,7 @@
{
"command_succeeded_event": {
"reply": {
"ok": 1.0,
"ok": 1,
"n": 0,
"writeErrors": [
{
Expand Down
Loading