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: data/change-streams/README.rst
+69-59Lines changed: 69 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,10 @@ Spec Test Runner
93
93
94
94
Before running the tests
95
95
96
-
- Create a MongoClient ``globalClient``, and connect to the server
96
+
- Create a MongoClient ``globalClient``, and connect to the server.
97
+
When executing tests against a sharded cluster, ``globalClient`` must only connect to one mongos. This is because tests
98
+
that set failpoints will only work consistently if both the ``configureFailPoint`` and failing commands are sent to the
99
+
same mongos.
97
100
98
101
For each YAML file, for each element in ``tests``:
99
102
@@ -110,13 +113,10 @@ For each YAML file, for each element in ``tests``:
110
113
111
114
- Create a new MongoClient ``client``
112
115
- Begin monitoring all APM events for ``client``. (If the driver uses global listeners, filter out all events that do not originate with ``client``). Filter out any "internal" commands (e.g. ``isMaster``)
113
-
- Using ``client``, create a changeStream ``changeStream`` against the specified ``target``. Use ``changeStreamPipeline`` and ``changeStreamOptions`` if they are non-empty
114
-
- Using ``globalClient``, run every operation in ``operations`` in serial against the server
115
-
- Wait until either:
116
-
117
-
- An error occurs
118
-
- All operations have been successful AND the changeStream has received as many changes as there are in ``result.success``
119
-
116
+
- Using ``client``, create a changeStream ``changeStream`` against the specified ``target``. Use ``changeStreamPipeline`` and ``changeStreamOptions`` if they are non-empty. Capture any error.
117
+
- If there was no error, use ``globalClient`` and run every operation in ``operations`` in serial against the server until all operations have been executed or an error is thrown. Capture any error.
118
+
- If there was no error and ``result.error`` is set, iterate ``changeStream`` once and capture any error.
119
+
- If there was no error and ``result.success`` is non-empty, iterate ``changeStream`` until it returns as many changes as there are elements in the ``result.success`` array or an error is thrown. Capture any error.
120
120
- Close ``changeStream``
121
121
- If there was an error:
122
122
@@ -131,8 +131,8 @@ For each YAML file, for each element in ``tests``:
131
131
- If there are any ``expectations``
132
132
133
133
- For each (``expected``, ``idx``) in ``expectations``
134
-
135
-
- Assert that ``actual[idx]`` MATCHES ``expected``
134
+
- If ``actual[idx]`` is a ``killCursors`` event, skip it and move to ``actual[idx+1]``.
135
+
- Else assert that ``actual[idx]`` MATCHES ``expected``
136
136
137
137
- Close the MongoClient ``client``
138
138
@@ -142,62 +142,72 @@ After running all tests
142
142
- Drop database ``database_name``
143
143
- Drop database ``database2_name``
144
144
145
+
Iterating the Change Stream
146
+
---------------------------
147
+
148
+
Although synchronous drivers must provide a `non-blocking mode of iteration <../change-streams.rst#not-blocking-on-iteration>`_, asynchronous drivers may not have such a mechanism. Those drivers with only a blocking mode of iteration should be careful not to iterate the change stream unnecessarily, as doing so could cause the test runner to block indefinitely. For this reason, the test runner procedure above advises drivers to take a conservative approach to iteration.
149
+
150
+
If the test expects an error and one was not thrown by either creating the change stream or executing the test's operations, iterating the change stream once allows for an error to be thrown by a ``getMore`` command. If the test does not expect any error, the change stream should be iterated only until it returns as many result documents as are expected by the test.
145
151
146
152
Prose Tests
147
153
===========
148
154
149
-
The following tests have not yet been automated, but MUST still be tested
155
+
The following tests have not yet been automated, but MUST still be tested. All tests SHOULD be run on both replica sets and sharded clusters unless otherwise specified:
150
156
151
157
#. ``ChangeStream`` must continuously track the last seen ``resumeToken``
152
158
#. ``ChangeStream`` will throw an exception if the server response is missing the resume token (if wire version is < 8, this is a driver-side error; for 8+, this is a server-side error)
153
-
#. ``ChangeStream`` will automatically resume one time on a resumable error (including `not master`) with the initial pipeline and options, except for the addition/update of a ``resumeToken``.
154
-
#. ``ChangeStream`` will not attempt to resume on any error encountered while executing an ``aggregate`` command.
155
-
#. ``ChangeStream`` will not attempt to resume after encountering error code 11601 (Interrupted), 136 (CappedPositionLost), or 237 (CursorKilled) while executing a ``getMore`` command.
159
+
#. After receiving a ``resumeToken``, ``ChangeStream`` will automatically resume one time on a resumable error with the initial pipeline and options, except for the addition/update of a ``resumeToken``.
160
+
#. ``ChangeStream`` will not attempt to resume on any error encountered while executing an ``aggregate`` command. Note that retryable reads may retry ``aggregate`` commands. Drivers should be careful to distinguish retries from resume attempts. Alternatively, drivers may specify `retryReads=false` or avoid using a [retryable error](../../retryable-reads/retryable-reads.rst#retryable-error) for this test.
161
+
#. **Removed**
156
162
#. ``ChangeStream`` will perform server selection before attempting to resume, using initial ``readPreference``
157
163
#. Ensure that a cursor returned from an aggregate command with a cursor id and an initial empty batch is not closed on the driver side.
158
164
#. The ``killCursors`` command sent during the "Resume Process" must not be allowed to throw an exception.
159
-
#. ``$changeStream`` stage for ``ChangeStream`` against a server ``>=4.0`` and ``<4.0.7`` that has not received any results yet MUST include a ``startAtOperationTime`` option when resuming a changestream.
160
-
#. ``ChangeStream`` will resume after a ``killCursors`` command is issued for its child cursor.
161
-
#. - For a ``ChangeStream`` under these conditions:
162
-
- Running against a server ``>=4.0.7``.
163
-
- The batch is empty or has been iterated to the last document.
164
-
- Expected result:
165
-
- ``getResumeToken`` must return the ``postBatchResumeToken`` from the current command response.
166
-
#. - For a ``ChangeStream`` under these conditions:
167
-
- Running against a server ``<4.0.7``.
168
-
- The batch is empty or has been iterated to the last document.
169
-
- Expected result:
170
-
- ``getResumeToken`` must return the ``_id`` of the last document returned if one exists.
171
-
- ``getResumeToken`` must return ``startAfter`` from the initial aggregate if the option was specified.
172
-
- ``getResumeToken`` must return ``resumeAfter`` from the initial aggregate if the option was specified.
173
-
- If neither the ``startAfter`` nor ``resumeAfter`` options were specified, the ``getResumeToken`` result must be empty.
174
-
#. - For a ``ChangeStream`` under these conditions:
175
-
- The batch is not empty.
176
-
- The batch has been iterated up to but not including the last element.
177
-
- Expected result:
178
-
- ``getResumeToken`` must return the ``_id`` of the previous document returned.
179
-
#. - For a ``ChangeStream`` under these conditions:
180
-
- The batch is not empty.
181
-
- The batch hasn’t been iterated at all.
182
-
- Only the initial ``aggregate`` command has been executed.
183
-
- Expected result:
184
-
- ``getResumeToken`` must return ``startAfter`` from the initial aggregate if the option was specified.
185
-
- ``getResumeToken`` must return ``resumeAfter`` from the initial aggregate if the option was specified.
186
-
- If neither the ``startAfter`` nor ``resumeAfter`` options were specified, the ``getResumeToken`` result must be empty.
187
-
#. - For a ``ChangeStream`` under these conditions:
188
-
- Running against a server ``>=4.0.7``.
189
-
- The batch is not empty.
190
-
- The batch hasn’t been iterated at all.
191
-
- The stream has iterated beyond a previous batch and a ``getMore`` command has just been executed.
192
-
- Expected result:
193
-
- ``getResumeToken`` must return the ``postBatchResumeToken`` from the previous command response.
194
-
#. - For a ``ChangeStream`` under these conditions:
195
-
- Running against a server ``<4.0.7``.
196
-
- The batch is not empty.
197
-
- The batch hasn’t been iterated at all.
198
-
- The stream has iterated beyond a previous batch and a ``getMore`` command has just been executed.
199
-
- Expected result:
200
-
- ``getResumeToken`` must return the ``_id`` of the previous document returned if one exists.
201
-
- ``getResumeToken`` must return ``startAfter`` from the initial aggregate if the option was specified.
202
-
- ``getResumeToken`` must return ``resumeAfter`` from the initial aggregate if the option was specified.
203
-
- If neither the ``startAfter`` nor ``resumeAfter`` options were specified, the ``getResumeToken`` result must be empty.
165
+
#. ``$changeStream`` stage for ``ChangeStream`` against a server ``>=4.0`` and ``<4.0.7`` that has not received any results yet MUST include a ``startAtOperationTime`` option when resuming a change stream.
166
+
#. **Removed**
167
+
#. For a ``ChangeStream`` under these conditions:
168
+
169
+
- Running against a server ``>=4.0.7``.
170
+
- The batch is empty or has been iterated to the last document.
171
+
172
+
Expected result:
173
+
174
+
- ``getResumeToken`` must return the ``postBatchResumeToken`` from the current command response.
175
+
176
+
#. For a ``ChangeStream`` under these conditions:
177
+
178
+
- Running against a server ``<4.0.7``.
179
+
- The batch is empty or has been iterated to the last document.
180
+
181
+
Expected result:
182
+
183
+
- ``getResumeToken`` must return the ``_id`` of the last document returned if one exists.
184
+
- ``getResumeToken`` must return ``resumeAfter`` from the initial aggregate if the option was specified.
185
+
- If ``resumeAfter`` was not specified, the ``getResumeToken`` result must be empty.
186
+
187
+
#. For a ``ChangeStream`` under these conditions:
188
+
189
+
- The batch is not empty.
190
+
- The batch has been iterated up to but not including the last element.
191
+
192
+
Expected result:
193
+
194
+
- ``getResumeToken`` must return the ``_id`` of the previous document returned.
195
+
196
+
#. For a ``ChangeStream`` under these conditions:
197
+
198
+
- The batch is not empty.
199
+
- The batch hasn’t been iterated at all.
200
+
- Only the initial ``aggregate`` command has been executed.
201
+
202
+
Expected result:
203
+
204
+
- ``getResumeToken`` must return ``startAfter`` from the initial aggregate if the option was specified.
205
+
- ``getResumeToken`` must return ``resumeAfter`` from the initial aggregate if the option was specified.
206
+
- If neither the ``startAfter`` nor ``resumeAfter`` options were specified, the ``getResumeToken`` result must be empty.
207
+
208
+
Note that this test cannot be run against sharded topologies because in that case the initial ``aggregate`` command only establishes cursors on the shards and always returns an empty ``firstBatch``.
209
+
210
+
#. **Removed**
211
+
#. **Removed**
212
+
#. ``$changeStream`` stage for ``ChangeStream`` started with ``startAfter`` against a server ``>=4.1.1`` that has not received any results yet MUST include a ``startAfter`` option and MUST NOT include a ``resumeAfter`` option when resuming a change stream.
213
+
#. ``$changeStream`` stage for ``ChangeStream`` started with ``startAfter`` against a server ``>=4.1.1`` that has received at least one result MUST include a ``resumeAfter`` option and MUST NOT include a ``startAfter`` option when resuming a change stream.
0 commit comments