@@ -22,18 +22,18 @@ cluster because the fail point is not supported by mongos.
22
22
The tests exercise the following scenarios:
23
23
24
24
- Single-statement write operations
25
- - Each test expecting a write result will encounter at-most one network error for the write command. Retry attempts
26
- should return without error and allow operation to succeed. Observation of the collection state will assert that the
27
- write occurred at-most once.
28
- - Each test expecting an error will encounter successive network errors for the write command. Observation of the
29
- collection state will assert that the write was never committed on the server.
25
+ - Each test expecting a write result will encounter at-most one network error for the write command. Retry attempts
26
+ should return without error and allow operation to succeed. Observation of the collection state will assert that
27
+ the write occurred at-most once.
28
+ - Each test expecting an error will encounter successive network errors for the write command. Observation of the
29
+ collection state will assert that the write was never committed on the server.
30
30
- Multi-statement write operations
31
- - Each test expecting a write result will encounter at-most one network error for some write command(s) in the batch.
32
- Retry attempts should return without error and allow the batch to ultimately succeed. Observation of the collection
33
- state will assert that each write occurred at-most once.
34
- - Each test expecting an error will encounter successive network errors for some write command in the batch. The batch
35
- will ultimately fail with an error, but observation of the collection state will assert that the failing write was
36
- never committed on the server. We may observe that earlier writes in the batch occurred at-most once.
31
+ - Each test expecting a write result will encounter at-most one network error for some write command(s) in the batch.
32
+ Retry attempts should return without error and allow the batch to ultimately succeed. Observation of the
33
+ collection state will assert that each write occurred at-most once.
34
+ - Each test expecting an error will encounter successive network errors for some write command in the batch. The batch
35
+ will ultimately fail with an error, but observation of the collection state will assert that the failing write was
36
+ never committed on the server. We may observe that earlier writes in the batch occurred at-most once.
37
37
38
38
We cannot test a scenario where the first and second attempts both encounter network errors but the write does actually
39
39
commit during one of those attempts. This is because (1) the fail point only triggers when a write would be committed
@@ -63,42 +63,9 @@ insert command (because all documents in the first command will be processed in
63
63
or delete that is split into two commands, the ` skip ` should be set to the number of statements in the first command to
64
64
allow the fail point to trigger on the second command.
65
65
66
- ## Command Construction Tests
67
-
68
- Drivers should also assert that command documents are properly constructed with or without a transaction ID, depending
69
- on whether the write operation is supported.
70
- [ Command Logging and Monitoring] ( ../../command-logging-and-monitoring/command-logging-and-monitoring.rst ) may be used to
71
- check for the presence of a ` txnNumber ` field in the command document. Note that command documents may always include an
72
- ` lsid ` field per the [ Driver Session] ( ../../sessions/driver-sessions.md ) specification.
73
-
74
- These tests may be run against both a replica set and shard cluster.
75
-
76
- Drivers should test that transaction IDs are never included in commands for unsupported write operations:
77
-
78
- - Write commands with unacknowledged write concerns (e.g. ` {w: 0} ` )
79
- - Unsupported single-statement write operations
80
- - ` updateMany() `
81
- - ` deleteMany() `
82
- - Unsupported multi-statement write operations
83
- - ` bulkWrite() ` that includes ` UpdateMany ` or ` DeleteMany `
84
- - Unsupported write commands
85
- - ` aggregate ` with write stage (e.g. ` $out ` , ` $merge ` )
86
-
87
- Drivers should test that transactions IDs are always included in commands for supported write operations:
88
-
89
- - Supported single-statement write operations
90
- - ` insertOne() `
91
- - ` updateOne() `
92
- - ` replaceOne() `
93
- - ` deleteOne() `
94
- - ` findOneAndDelete() `
95
- - ` findOneAndReplace() `
96
- - ` findOneAndUpdate() `
97
- - Supported multi-statement write operations
98
- - ` insertMany() ` with ` ordered=true `
99
- - ` insertMany() ` with ` ordered=false `
100
- - ` bulkWrite() ` with ` ordered=true ` (no ` UpdateMany ` or ` DeleteMany ` )
101
- - ` bulkWrite() ` with ` ordered=false ` (no ` UpdateMany ` or ` DeleteMany ` )
66
+ ## ~~ Command Construction Tests~~
67
+
68
+ The command construction prose tests have been removed in favor of command event assertions in the unified format tests.
102
69
103
70
## Prose Tests
104
71
@@ -109,7 +76,7 @@ The following tests ensure that retryable writes work properly with replica sets
109
76
For this test, execute a write operation, such as ` insertOne ` , which should generate an exception. Assert that the error
110
77
message is the replacement error message:
111
78
112
- ```
79
+ ``` text
113
80
This MongoDB deployment does not support retryable writes. Please add
114
81
retryWrites=false to your connection string.
115
82
```
@@ -127,23 +94,23 @@ This test MUST be implemented by any driver that implements the CMAP specificati
127
94
This test requires MongoDB 4.3.4+ for both the ` errorLabels ` and ` blockConnection ` fail point options.
128
95
129
96
1 . Create a client with maxPoolSize=1 and retryWrites=true. If testing against a sharded deployment, be sure to connect
130
- to only a single mongos.
97
+ to only a single mongos.
131
98
132
99
2 . Enable the following failpoint:
133
100
134
- ``` javascript
135
- {
136
- configureFailPoint: " failCommand" ,
137
- mode: { times: 1 },
138
- data: {
139
- failCommands: [" insert" ],
140
- errorCode: 91 ,
141
- blockConnection: true ,
142
- blockTimeMS: 1000 ,
143
- errorLabels: [" RetryableWriteError" ]
144
- }
145
- }
146
- ```
101
+ ``` javascript
102
+ {
103
+ configureFailPoint: " failCommand" ,
104
+ mode: { times: 1 },
105
+ data: {
106
+ failCommands: [" insert" ],
107
+ errorCode: 91 ,
108
+ blockConnection: true ,
109
+ blockTimeMS: 1000 ,
110
+ errorLabels: [" RetryableWriteError" ]
111
+ }
112
+ }
113
+ ```
147
114
148
115
3. Start two threads and attempt to perform an ` insertOne` simultaneously on both.
149
116
@@ -175,47 +142,47 @@ test to cover the same sequence of events.
175
142
176
143
2. Configure a fail point with error code ` 91` (ShutdownInProgress):
177
144
178
- ``` javascript
179
- {
180
- configureFailPoint: " failCommand" ,
181
- mode: {times: 1 },
182
- data: {
183
- failCommands: [" insert" ],
184
- errorLabels: [" RetryableWriteError" ],
185
- writeConcernError: { code: 91 }
186
- }
187
- }
188
- ```
145
+ ` ` ` javascript
146
+ {
147
+ configureFailPoint: "failCommand",
148
+ mode: {times: 1},
149
+ data: {
150
+ failCommands: ["insert"],
151
+ errorLabels: ["RetryableWriteError"],
152
+ writeConcernError: { code: 91 }
153
+ }
154
+ }
155
+ ` ` `
189
156
190
157
3. Via the command monitoring CommandSucceededEvent, configure a fail point with error code ` 10107` (NotWritablePrimary)
191
- and a NoWritesPerformed label:
192
-
193
- ``` javascript
194
- {
195
- configureFailPoint: " failCommand" ,
196
- mode: {times: 1 },
197
- data: {
198
- failCommands: [" insert" ],
199
- errorCode: 10107 ,
200
- errorLabels: [" RetryableWriteError" , " NoWritesPerformed" ]
201
- }
202
- }
203
- ```
204
-
205
- Drivers SHOULD only configure the ` 10107 ` fail point command if the the succeeded event is for the ` 91 ` error
206
- configured in step 2.
158
+ and a NoWritesPerformed label:
159
+
160
+ ` ` ` javascript
161
+ {
162
+ configureFailPoint: "failCommand",
163
+ mode: {times: 1},
164
+ data: {
165
+ failCommands: ["insert"],
166
+ errorCode: 10107,
167
+ errorLabels: ["RetryableWriteError", "NoWritesPerformed"]
168
+ }
169
+ }
170
+ ` ` `
171
+
172
+ Drivers SHOULD only configure the ` 10107` fail point command if the the succeeded event is for the ` 91` error
173
+ configured in step 2.
207
174
208
175
4. Attempt an ` insertOne` operation on any record for any database and collection . For the resulting error, assert that
209
- the associated error code is ` 91 ` .
176
+ the associated error code is ` 91` .
210
177
211
178
5. Disable the fail point:
212
179
213
- ``` javascript
214
- {
215
- configureFailPoint: " failCommand" ,
216
- mode: " off"
217
- }
218
- ```
180
+ ` ` ` javascript
181
+ {
182
+ configureFailPoint: "failCommand",
183
+ mode: "off"
184
+ }
185
+ ` ` `
219
186
220
187
### 4. Test that in a sharded cluster writes are retried on a different mongos when one is available.
221
188
@@ -229,24 +196,24 @@ This test MUST be executed against a sharded cluster that has at least two mongo
229
196
> coverage tool, etc.
230
197
231
198
1. Create two clients ` s0` and ` s1` that each connect to a single mongos from the sharded cluster . They must not connect
232
- to the same mongos.
199
+ to the same mongos.
233
200
234
201
2. Configure the following fail point for both ` s0` and ` s1` :
235
202
236
- ``` javascript
237
- {
238
- configureFailPoint: " failCommand" ,
239
- mode: { times: 1 },
240
- data: {
241
- failCommands: [" insert" ],
242
- errorCode: 6 ,
243
- errorLabels: [" RetryableWriteError" ]
244
- }
245
- }
246
- ```
203
+ ` ` ` javascript
204
+ {
205
+ configureFailPoint: "failCommand",
206
+ mode: { times: 1 },
207
+ data: {
208
+ failCommands: ["insert"],
209
+ errorCode: 6,
210
+ errorLabels: ["RetryableWriteError"]
211
+ }
212
+ }
213
+ ` ` `
247
214
248
215
3. Create a client ` client` with ` retryWrites=true` that connects to the cluster using the same two mongoses as ` s0` and
249
- ` s1 ` .
216
+ ` s1` .
250
217
251
218
4. Enable failed command event monitoring for ` client` .
252
219
@@ -270,72 +237,67 @@ debugger, code coverage tool, etc.
270
237
271
238
2. Configure the following fail point for ` s0` :
272
239
273
- ``` javascript
274
- {
275
- configureFailPoint: " failCommand" ,
276
- mode: { times: 1 },
277
- data: {
278
- failCommands: [" insert" ],
279
- errorCode: 6 ,
280
- errorLabels: [" RetryableWriteError" ],
281
- closeConnection: true
282
- }
283
- }
284
- ```
240
+ ` ` ` javascript
241
+ {
242
+ configureFailPoint: "failCommand",
243
+ mode: { times: 1 },
244
+ data: {
245
+ failCommands: ["insert"],
246
+ errorCode: 6,
247
+ errorLabels: ["RetryableWriteError"],
248
+ closeConnection: true
249
+ }
250
+ }
251
+ ` ` `
285
252
286
253
3. Create a client ` client` with ` directConnection=false` (when not set by default) and ` retryWrites=true` that connects
287
- to the cluster using the same single mongos as ` s0 ` .
254
+ to the cluster using the same single mongos as ` s0` .
288
255
289
256
4. Enable succeeded and failed command event monitoring for ` client` .
290
257
291
258
5. Execute an ` insert` command with ` client` . Assert that the command succeeded.
292
259
293
260
6. Assert that exactly one failed command event and one succeeded command event occurred . Assert that both events
294
- occurred on the same mongos.
261
+ occurred on the same mongos.
295
262
296
263
7. Disable the fail point on ` s0` .
297
264
298
265
## Changelog
299
266
267
+ - 2024 - 10 - 29 : Convert command construction tests to unified format.
268
+
300
269
- 2024 - 05 - 30 : Migrated from reStructuredText to Markdown.
301
270
302
271
- 2024 - 02 - 27 : Convert legacy retryable writes tests to unified format.
303
272
304
- - 2024-02-21: Update prose test 4 and 5 to workaround SDAM behavior preventing\
305
- execution of deprioritization code
306
- paths.
273
+ - 2024 - 02 - 21 : Update prose test 4 and 5 to workaround SDAM behavior preventing execution of deprioritization code paths.
307
274
308
275
- 2024 - 01 - 05 : Fix typo in prose test title.
309
276
310
- - 2024-01-03: Note server version requirements for fail point options and revise\
311
- tests to specify the ` errorLabels `
312
- option at the top-level instead of within ` writeConcernError ` .
277
+ - 2024 - 01 - 03 : Note server version requirements for fail point options and revise tests to specify the ` errorLabels`
278
+ option at the top- level instead of within ` writeConcernError` .
313
279
314
280
- 2023 - 08 - 26 : Add prose tests for retrying in a sharded cluster.
315
281
316
- - 2022-08-30: Add prose test verifying correct error handling for errors with\
317
- the NoWritesPerformed label, which is to
318
- return the original error.
282
+ - 2022 - 08 - 30 : Add prose test verifying correct error handling for errors with the NoWritesPerformed label, which is to
283
+ return the original error.
319
284
320
285
- 2022 - 04 - 22 : Clarifications to ` serverless` and ` useMultipleMongoses` .
321
286
322
- - 2021-08-27: Add ` serverless ` to ` runOn ` . Clarify behavior of\
323
- ` useMultipleMongoses ` for ` LoadBalanced ` topologies.
287
+ - 2021 - 08 - 27 : Add ` serverless` to ` runOn` . Clarify behavior of ` useMultipleMongoses` for ` LoadBalanced` topologies.
324
288
325
289
- 2021 - 04 - 23 : Add ` load-balanced` to test topology requirements.
326
290
327
291
- 2021 - 03 - 24 : Add prose test verifying ` PoolClearedErrors` are retried.
328
292
329
- - 2019-10-21: Add ` errorLabelsContain ` and ` errorLabelsContain ` fields to\
330
- ` result `
293
+ - 2019 - 10 - 21 : Add ` errorLabelsContain` and ` errorLabelsContain` fields to ` result`
331
294
332
295
- 2019 - 08 - 07 : Add Prose Tests section
333
296
334
297
- 2019 - 06 - 07 : Mention $merge stage for aggregate alongside $out
335
298
336
- - 2019-03-01: Add top-level ` runOn ` field to denote server version and/or\
337
- topology requirements requirements for the
338
- test file. Removes the ` minServerVersion ` and ` maxServerVersion ` top-level fields, which are now expressed within
339
- ` runOn ` elements.
299
+ - 2019 - 03 - 01 : Add top- level ` runOn` field to denote server version and/ or topology requirements requirements for the
300
+ test file . Removes the ` minServerVersion` and ` maxServerVersion` top- level fields, which are now expressed within
301
+ ` runOn` elements.
340
302
341
- Add test-level ` useMultipleMongoses ` field.
303
+ Add test- level ` useMultipleMongoses` field.
0 commit comments