| 1 |
=================== |
| 2 |
Max Staleness Tests |
| 3 |
=================== |
| 4 |
|
| 5 |
This directory contains platform-independent tests that drivers can use |
| 6 |
to prove their conformance to the Max Staleness Spec. The tests |
| 7 |
are provided in both YAML and JSON formats, and drivers may test against |
| 8 |
whichever format is more convenient for them. |
| 9 |
|
| 10 |
Test Format and Use |
| 11 |
------------------- |
| 12 |
|
| 13 |
YAML files contain the following setup for each test: |
| 14 |
|
| 15 |
- ``heartbeatFrequencyMS``: optional int |
| 16 |
|
| 17 |
- ``topology_description``: the state of a mocked cluster |
| 18 |
|
| 19 |
- ``type``: the TopologyType |
| 20 |
|
| 21 |
- ``servers``: a list of ServerDescriptions, each with: |
| 22 |
|
| 23 |
- ``address``: a "host:port" |
| 24 |
|
| 25 |
- ``type``: a ServerType |
| 26 |
|
| 27 |
- ``avg_rtt_ms``: average round trip time in milliseconds [1]_ |
| 28 |
|
| 29 |
- ``lastWrite``: subdocument |
| 30 |
|
| 31 |
- ``lastWriteDate``: nonzero int64, milliseconds since some past time |
| 32 |
|
| 33 |
- ``maxWireVersion``: an int |
| 34 |
|
| 35 |
- ``lastUpdateTime``: milliseconds since the Unix epoch |
| 36 |
|
| 37 |
- ``read_preference``: a read preference document |
| 38 |
|
| 39 |
For each test, create a MongoClient. |
| 40 |
Configure it with the heartbeatFrequencyMS specified by the test, |
| 41 |
or accept the driver's default heartbeatFrequencyMS if the test omits this field. |
| 42 |
|
| 43 |
(Single-threaded and multi-threaded clients now make heartbeatFrequencyMS configurable. |
| 44 |
This is a change in Server Discovery and Monitoring to support maxStalenessSeconds. |
| 45 |
Before, multi-threaded clients were allowed to make it configurable or not.) |
| 46 |
|
| 47 |
For each test, create a new TopologyDescription object initialized with the |
| 48 |
values from ``topology_description``. Initialize ServerDescriptions from the |
| 49 |
provided data. Create a ReadPreference object initialized with the values |
| 50 |
from ``read_preference``. Select servers that match the ReadPreference. |
| 51 |
|
| 52 |
Each test specifies that it expects an error, or specifies two sets of servers: |
| 53 |
|
| 54 |
- ``error: true`` |
| 55 |
- ``suitable_servers``: the set of servers in the TopologyDescription |
| 56 |
that are suitable for the ReadPreference, without taking ``avg_rtt_ms`` |
| 57 |
into account. |
| 58 |
- ``in_latency_window``: the set of suitable servers whose round trip time |
| 59 |
qualifies them according to the default latency threshold of 15ms. |
| 60 |
In each test there is one server in the latency window, to ensure |
| 61 |
tests pass or fail deterministically. |
| 62 |
|
| 63 |
If the file contains ``error: true``, drivers MUST test that they throw an |
| 64 |
error during server selection due to an invalid read preference. For other |
| 65 |
files, drivers MUST test that they correctly select the set of servers in |
| 66 |
``in_latency_window``. |
| 67 |
|
| 68 |
Drivers MAY also test that before filtration by latency, they select the |
| 69 |
specified set of "suitable" servers. |
| 70 |
|
| 71 |
.. [1] ``avg_rtt_ms`` is included merely for consistency with |
| 72 |
Server Selection tests. It is not significant in Max Staleness tests. |