You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: source/connection-monitoring-and-pooling/tests/README.rst
+11-206
Original file line number
Diff line number
Diff line change
@@ -11,221 +11,26 @@ Connection Monitoring and Pooling (CMAP)
11
11
12
12
Introduction
13
13
============
14
+
Drivers MUST implement all of the following types of CMAP tests:
14
15
15
-
The YAML and JSON files in this directory are platform-independent tests that
16
-
drivers can use to prove their conformance to the Connection Monitoring and Pooling (CMAP) Spec.
17
-
18
-
Several prose tests, which are not easily expressed in YAML, are also presented
19
-
in this file. Those tests will need to be manually implemented by each driver.
20
-
21
-
Common Test Format
22
-
==================
23
-
24
-
Each YAML file has the following keys:
25
-
26
-
- ``version``: A version number indicating the expected format of the spec tests (current version = 1)
27
-
- ``style``: A string indicating what style of tests this file contains. Contains one of the following:
28
-
29
-
- ``"unit"``: a test that may be run without connecting to a MongoDB deployment.
30
-
- ``"integration"``: a test that MUST be run against a real MongoDB deployment.
31
-
32
-
- ``description``: A text description of what the test is meant to assert
33
-
34
-
Unit Test Format:
35
-
=================
36
-
37
-
All Unit Tests have some of the following fields:
38
-
39
-
- ``poolOptions``: If present, connection pool options to use when creating a pool;
40
-
both `standard ConnectionPoolOptions <https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#connection-pool-options-1>`__
41
-
and the following test-specific options are allowed:
42
-
43
-
- ``backgroundThreadIntervalMS``: A time interval between the end of a
44
-
`Background Thread Run <https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#background-thread>`__
45
-
and the beginning of the next Run. If a Connection Pool does not implement a Background Thread, the Test Runner MUST ignore the option.
46
-
If the option is not specified, an implementation is free to use any value it finds reasonable.
47
-
48
-
Possible values (0 is not allowed):
49
-
50
-
- A negative value: never begin a Run.
51
-
- A positive value: the interval between Runs in milliseconds.
52
-
53
-
- ``operations``: A list of operations to perform. All operations support the following fields:
54
-
55
-
- ``name``: A string describing which operation to issue.
56
-
- ``thread``: The name of the thread in which to run this operation. If not specified, runs in the default thread
57
-
58
-
- ``error``: Indicates that the main thread is expected to error during this test. An error may include of the following fields:
59
-
60
-
- ``type``: the type of error emitted
61
-
- ``message``: the message associated with that error
62
-
- ``address``: Address of pool emitting error
63
-
64
-
- ``events``: An array of all connection monitoring events expected to occur while running ``operations``. An event may contain any of the following fields
65
-
66
-
- ``type``: The type of event emitted
67
-
- ``address``: The address of the pool emitting the event
68
-
- ``connectionId``: The id of a connection associated with the event
69
-
- ``options``: Options used to create the pool
70
-
- ``reason``: A reason giving mroe information on why the event was emitted
71
-
72
-
- ``ignore``: An array of event names to ignore
73
-
74
-
Valid Unit Test Operations are the following:
75
-
76
-
- ``start(target)``: Starts a new thread named ``target``
77
-
78
-
- ``target``: The name of the new thread to start
79
-
80
-
- ``wait(ms)``: Sleep the current thread for ``ms`` milliseconds
81
-
82
-
- ``ms``: The number of milliseconds to sleep the current thread for
83
-
84
-
- ``waitForThread(target)``: wait for thread ``target`` to finish executing. Propagate any errors to the main thread.
85
-
86
-
- ``target``: The name of the thread to wait for.
87
-
88
-
- ``waitForEvent(event, count, timeout)``: block the current thread until ``event`` has occurred ``count`` times
89
-
90
-
- ``event``: The name of the event
91
-
- ``count``: The number of times the event must occur (counting from the start of the test)
92
-
- ``timeout``: If specified, time out with an error after waiting for this many milliseconds without seeing the required events
93
-
94
-
- ``label = pool.checkOut()``: call ``checkOut`` on pool, returning the checked out connection
95
-
96
-
- ``label``: If specified, associate this label with the returned connection, so that it may be referenced in later operations
97
-
98
-
- ``pool.checkIn(connection)``: call ``checkIn`` on pool
99
-
100
-
- ``connection``: A string label identifying which connection to check in. Should be a label that was previously set with ``checkOut``
101
-
102
-
- ``pool.clear()``: call ``clear`` on Pool
103
-
104
-
- ``interruptInUseConnections``: Determines whether "in use" connections should be also interrupted
105
-
106
-
- ``pool.close()``: call ``close`` on Pool
107
-
- ``pool.ready()``: call ``ready`` on Pool
108
-
109
-
110
-
Integration Test Format
111
-
=======================
112
-
113
-
The integration test format is identical to the unit test format with
114
-
the addition of the following fields to each test:
115
-
116
-
- ``runOn`` (optional): An array of server version and/or topology requirements
117
-
for which the tests can be run. If the test environment satisfies one or more
118
-
of these requirements, the tests may be executed; otherwise, this test should
119
-
be skipped. If this field is omitted, the tests can be assumed to have no
120
-
particular requirements and should be executed. Each element will have some or
121
-
all of the following fields:
122
-
123
-
- ``minServerVersion`` (optional): The minimum server version (inclusive)
124
-
required to successfully run the tests. If this field is omitted, it should
125
-
be assumed that there is no lower bound on the required server version.
126
-
127
-
- ``maxServerVersion`` (optional): The maximum server version (inclusive)
128
-
against which the tests can be run successfully. If this field is omitted,
129
-
it should be assumed that there is no upper bound on the required server
130
-
version.
131
-
132
-
- ``failPoint``: optional, a document containing a ``configureFailPoint``
133
-
command to run against the endpoint being used for the test.
134
-
135
-
- ``poolOptions.appName`` (optional): appName attribute to be set in connections, which will be affected by the fail point.
136
-
137
-
Spec Test Match Function
138
-
========================
139
-
140
-
The definition of MATCH or MATCHES in the Spec Test Runner is as follows:
141
-
142
-
- MATCH takes two values, ``expected`` and ``actual``
143
-
- Notation is "Assert [actual] MATCHES [expected]
144
-
- Assertion passes if ``expected`` is a subset of ``actual``, with the values ``42`` and ``"42"`` acting as placeholders for "any value"
145
-
146
-
Pseudocode implementation of ``actual`` MATCHES ``expected``:
147
-
148
-
::
149
-
150
-
If expected is "42" or 42:
151
-
Assert that actual exists (is not null or undefined)
152
-
Else:
153
-
Assert that actual is of the same JSON type as expected
154
-
If expected is a JSON array:
155
-
For every idx/value in expected:
156
-
Assert that actual[idx] MATCHES value
157
-
Else if expected is a JSON object:
158
-
For every key/value in expected
159
-
Assert that actual[key] MATCHES value
160
-
Else:
161
-
Assert that expected equals actual
162
-
163
-
Unit Test Runner:
164
-
=================
165
-
166
-
For the unit tests, the behavior of a Connection is irrelevant beyond the need to asserting ``connection.id``. Drivers MAY use a mock connection class for testing the pool behavior in unit tests
167
-
168
-
For each YAML file with ``style: unit``:
169
-
170
-
- Create a Pool ``pool``, subscribe and capture any Connection Monitoring events emitted in order.
171
-
172
-
- If ``poolOptions`` is specified, use those options to initialize both pools
173
-
- The returned pool must have an ``address`` set as a string value.
174
-
175
-
- Process each ``operation`` in ``operations`` (on the main thread)
176
-
177
-
- If a ``thread`` is specified, the main thread MUST schedule the operation to execute in the corresponding thread. Otherwise, execute the operation directly in the main thread.
178
-
179
-
- If ``error`` is presented
180
-
181
-
- Assert that an actual error ``actualError`` was thrown by the main thread
182
-
- Assert that ``actualError`` MATCHES ``error``
183
-
184
-
- Else:
185
-
186
-
- Assert that no errors were thrown by the main thread
187
-
188
-
- calculate ``actualEvents`` as every Connection Event emitted whose ``type`` is not in ``ignore``
189
-
- if ``events`` is not empty, then for every ``idx``/``expectedEvent`` in ``events``
190
-
191
-
- Assert that ``actualEvents[idx]`` exists
192
-
- Assert that ``actualEvents[idx]`` MATCHES ``expectedEvent``
193
-
194
-
195
-
It is important to note that the ``ignore`` list is used for calculating ``actualEvents``, but is NOT used for the ``waitForEvent`` command
196
-
197
-
Integration Test Runner
198
-
=======================
199
-
200
-
The steps to run the integration tests are the same as those used to run the
201
-
unit tests with the following modifications:
202
-
203
-
- The integration tests MUST be run against an actual endpoint. If the
204
-
deployment being tested contains multiple endpoints, then the runner MUST
205
-
only use one of them to run the tests against.
206
-
207
-
- For each test, if `failPoint` is specified, its value is a
208
-
``configureFailPoint`` command. Run the command on the admin database of the
209
-
endpoint being tested to enable the fail point.
210
-
211
-
- At the end of each test, any enabled fail point MUST be disabled to avoid
212
-
spurious failures in subsequent tests. The fail point may be disabled like
213
-
so::
214
-
215
-
db.adminCommand({
216
-
configureFailPoint: <fail point name>,
217
-
mode: "off"
218
-
});
219
-
16
+
* Pool unit and integration tests as described in `cmap-format/README.rst <./cmap-format/README.rst>`__
17
+
* Pool prose tests as described below in `Prose Tests`_
18
+
* Logging tests as described below in `Logging Tests`_
220
19
221
20
Prose Tests
222
21
===========
223
22
224
-
The following tests have not yet been automated, but MUST still be tested
23
+
The following tests have not yet been automated, but MUST still be tested:
225
24
226
25
#. All ConnectionPoolOptions MUST be specified at the MongoClient level
227
26
#. All ConnectionPoolOptions MUST be the same for all pools created by a MongoClient
228
27
#. A user MUST be able to specify all ConnectionPoolOptions via a URI string
229
28
#. A user MUST be able to subscribe to Connection Monitoring Events in a manner idiomatic to their language and driver
230
29
#. When a check out attempt fails because connection set up throws an error,
231
30
assert that a ConnectionCheckOutFailedEvent with reason="connectionError" is emitted.
31
+
32
+
Logging Tests
33
+
=============
34
+
35
+
Tests for connection pool logging can be found in the `/logging <./logging>`__ subdirectory and are written in the
36
+
`Unified Test Format <../../unified-test-format/unified-test-format.rst>`__.
0 commit comments