• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Jan-2020-

monitoring/H08-Jan-2020-1,2311,214

rs/H08-Jan-2020-7,5106,839

sharded/H08-Jan-2020-891793

single/H08-Jan-2020-940812

README.rstH A D08-Jan-20204.4 KiB11687

README.rst

1=====================================
2Server Discovery And Monitoring Tests
3=====================================
4
5The YAML and JSON files in this directory tree are platform-independent tests
6that drivers can use to prove their conformance to the
7Server Discovery And Monitoring Spec.
8
9Version
10-------
11
12Files in the "specifications" repository have no version scheme.
13They are not tied to a MongoDB server version,
14and it is our intention that each specification moves from "draft" to "final"
15with no further versions; it is superseded by a future spec, not revised.
16
17However, implementers must have stable sets of tests to target.
18As test files evolve they will be occasionally tagged like
19"server-discovery-tests-2014-09-10", until the spec is final.
20
21Format
22------
23
24Each YAML file has the following keys:
25
26- description: Some text.
27- uri: A connection string.
28- phases: An array of "phase" objects.
29
30A "phase" of the test sends inputs to the client, then tests the client's
31resulting TopologyDescription. Each phase object has two keys:
32
33- responses: An array of "response" objects.
34- outcome: An "outcome" object representing the TopologyDescription.
35
36A response is a pair of values:
37
38- The source, for example "a:27017".
39  This is the address the client sent the "ismaster" command to.
40- An ismaster response, for example `{ok: 1, ismaster: true}`.
41  If the response includes an electionId it is shown in extended JSON like
42  `{"$oid": "000000000000000000000002"}`.
43  The empty response `{}` indicates a network error
44  when attempting to call "ismaster".
45
46An "outcome" represents the correct TopologyDescription that results from
47processing the responses in the phases so far. It has the following keys:
48
49- topologyType: A string like "ReplicaSetNoPrimary".
50- setName: A string with the expected replica set name, or null.
51- servers: An object whose keys are addresses like "a:27017", and whose values
52  are "server" objects.
53- logicalSessionTimeoutMinutes: null or an integer.
54- compatible: absent or a bool.
55
56A "server" object represents a correct ServerDescription within the client's
57current TopologyDescription. It has the following keys:
58
59- type: A ServerType name, like "RSSecondary".
60- setName: A string with the expected replica set name, or null.
61- setVersion: absent or an integer.
62- electionId: absent, null, or an ObjectId.
63- logicalSessionTimeoutMinutes: absent, null, or an integer.
64- minWireVersion: absent or an integer.
65- maxWireVersion: absent or an integer.
66
67Use as unittests
68----------------
69
70Mocking
71~~~~~~~
72
73Drivers should be able to test their server discovery and monitoring logic
74without any network I/O, by parsing ismaster responses from the test file
75and passing them into the driver code. Parts of the client and monitoring
76code may need to be mocked or subclassed to achieve this. `A reference
77implementation for PyMongo 3.x is available here
78<https://github.com/mongodb/mongo-python-driver/blob/3.0-dev/test/test_discovery_and_monitoring.py>`_.
79
80Initialization
81~~~~~~~~~~~~~~
82
83For each file, create a fresh client object initialized with the file's "uri".
84
85All files in the "single" directory include a connection string with one host
86and no "replicaSet" option.
87Set the client's initial TopologyType to Single, however that is achieved using the client's API.
88(The spec says "The user MUST be able to set the initial TopologyType to Single"
89without specifying how.)
90
91All files in the "sharded" directory include a connection string with multiple hosts
92and no "replicaSet" option.
93Set the client's initial TopologyType to Unknown or Sharded, depending on the client's API.
94
95All files in the "rs" directory include a connection string with a "replicaSet" option.
96Set the client's initial TopologyType to ReplicaSetNoPrimary.
97(For most clients, parsing a connection string with a "replicaSet" option
98automatically sets the TopologyType to ReplicaSetNoPrimary.)
99
100Test Phases
101~~~~~~~~~~~
102
103For each phase in the file, parse the "responses" array.
104Pass in the responses in order to the driver code.
105If a response is the empty object `{}`, simulate a network error.
106
107Once all responses are processed, assert that the phase's "outcome" object
108is equivalent to the driver's current TopologyDescription.
109
110Some fields such as "logicalSessionTimeoutMinutes" or "compatible" were added
111later and haven't been added to all test files. If these fields are present,
112test that they are equivalent to the fields of the driver's current
113TopologyDescription.
114
115Continue until all phases have been executed.
116