|
| 1 | +.. role:: javascript(code) |
| 2 | + :language: javascript |
| 3 | + |
| 4 | +================== |
| 5 | +Command Monitoring |
| 6 | +================== |
| 7 | + |
| 8 | +.. contents:: |
| 9 | + |
| 10 | +-------- |
| 11 | + |
| 12 | +Testing |
| 13 | +======= |
| 14 | + |
| 15 | +Tests are provided in YML and JSON format to assert proper upconversion of commands. |
| 16 | + |
| 17 | +Database and Collection Names |
| 18 | +----------------------------- |
| 19 | + |
| 20 | +The collection under test is specified in each test file with the fields |
| 21 | +``database_name`` and ``collection_name``. |
| 22 | + |
| 23 | +Data |
| 24 | +---- |
| 25 | + |
| 26 | +The ``data`` at the beginning of each test file is the data that should exist in the |
| 27 | +collection under test before each test run. |
| 28 | + |
| 29 | +Expectations |
| 30 | +------------ |
| 31 | + |
| 32 | +Fake Placeholder Values |
| 33 | +``````````````````````` |
| 34 | + |
| 35 | +When an attribute in an expectation contains the value ``"42"``, ``42`` or ``""``, this is a fake |
| 36 | +placeholder value indicating that a special case MUST be tested that could not be |
| 37 | +expressed in a YAML or JSON test. These cases are as follows: |
| 38 | + |
| 39 | +Cursor Matching |
| 40 | +^^^^^^^^^^^^^^^ |
| 41 | + |
| 42 | +When encountering a ``cursor`` or ``getMore`` value of ``"42"`` in a test, the driver MUST assert |
| 43 | +that the values are equal to each other and greater than zero. |
| 44 | + |
| 45 | +Errors |
| 46 | +^^^^^^ |
| 47 | + |
| 48 | +For write errors, ``code`` values of ``42`` MUST assert that the value is present and |
| 49 | +greater than zero. ``errmsg`` values of ``""`` MUST assert that the value is not empty |
| 50 | +(a string of length greater than 1). |
| 51 | + |
| 52 | +OK Values |
| 53 | +^^^^^^^^^ |
| 54 | + |
| 55 | +The server is inconsistent on whether the ok values returned are integers or doubles so |
| 56 | +for simplicity the tests specify all expected values as doubles. Server 'ok' values of |
| 57 | +integers MUST be converted to doubles for comparison with the expected values. |
| 58 | + |
| 59 | +Additional Values |
| 60 | +````````````````` |
| 61 | + |
| 62 | +The expected events provide the minimum data that is required and can be tested. It is |
| 63 | +possible for more values to be present in the events, such as extra data provided when |
| 64 | +using sharded clusters or ``nModified`` field in updates. The driver MUST assert the |
| 65 | +expected data is present and also MUST allow for additional data to be present as well |
| 66 | +at the top level of the command document or reply document. |
| 67 | + |
| 68 | +For example, say the client sends a causally-consistent "distinct" command with |
| 69 | +readConcern level "majority", like:: |
| 70 | + |
| 71 | + { |
| 72 | + "distinct": "collection", |
| 73 | + "key": "key", |
| 74 | + "readConcern":{ |
| 75 | + "afterClusterTime": {"$timestamp":{"t":1522336030,"i":1}}, |
| 76 | + "level":"majority" |
| 77 | + }, |
| 78 | + "$clusterTime": { |
| 79 | + "clusterTime": { "$timestamp": { "i": 1, "t": 1522335530 } }, |
| 80 | + "signature": { |
| 81 | + "hash": { "$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type": "00" }, |
| 82 | + "keyId": { "$numberLong": "0" } |
| 83 | + } |
| 84 | + }, |
| 85 | + "lsid": { |
| 86 | + "id": { "$binary": "RaigP3oASqu+galPvRAfcg==", "$type": "04" } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | +Then it would pass a command-started event like the following YAML, because the |
| 91 | +fields not mentioned in the YAML are ignored:: |
| 92 | + |
| 93 | + command: |
| 94 | + distinct: collection |
| 95 | + key: key |
| 96 | + |
| 97 | +However, if there are fields in command subdocuments that are not mentioned in |
| 98 | +the YAML, then the command does *not* pass the test:: |
| 99 | + |
| 100 | + command: |
| 101 | + distinct: collection |
| 102 | + key: key |
| 103 | + # Fails because the expected readConcern has no "afterClusterTime". |
| 104 | + readConcern: |
| 105 | + level: majority |
| 106 | + |
| 107 | +Ignoring Tests Based On Server Version or Topology Type |
| 108 | +``````````````````````````````````````````````````````` |
| 109 | + |
| 110 | +Due to variations in server behavior, some tests may not be valid and MUST NOT be run on |
| 111 | +certain server versions or topology types. These tests are indicated with any of the |
| 112 | +following fields, which will be optionally provided at the ``description`` level of each |
| 113 | +test: |
| 114 | + |
| 115 | +- ``ignore_if_server_version_greater_than`` (optional): If specified, the test MUST be |
| 116 | + skipped if the minor version of the server is greater than this minor version. The |
| 117 | + server's patch version MUST NOT be considered. For example, a value of ``3.0`` implies |
| 118 | + that the test can run on server version ``3.0.15`` but not ``3.1.0``. |
| 119 | + |
| 120 | +- ``ignore_if_server_version_less_than`` (optional): If specified, the test MUST be |
| 121 | + skipped if the minor version of the server is less than this minor version. The |
| 122 | + server's patch version MUST NOT be considered. For example, a value of ``3.2`` implies |
| 123 | + that the test can run on server version ``3.2.0`` but not ``3.0.15``. |
| 124 | + |
| 125 | +- ``ignore_if_topology_type`` (optional): An array of server topologies for which the test |
| 126 | + MUST be skipped. Valid topologies are "single", "replicaset", and "sharded". |
| 127 | + |
| 128 | +Tests that have none of these fields MUST be run on all supported server versions. |
0 commit comments