Skip to content

Commit c682958

Browse files
committed
CSHARP-2266: Synchronize JSON powered retryable writes tests
1 parent 685a6d8 commit c682958

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2688
-60
lines changed

tests/MongoDB.Driver.Tests.Dotnet/Specifications/retryable-writes/tests/README.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ that drivers can use to prove their conformance to the Retryable Writes spec.
1515
Several prose tests, which are not easily expressed in YAML, are also presented
1616
in this file. Those tests will need to be manually implemented by each driver.
1717

18-
Tests will require a MongoClient with ``retryWrites`` enabled. Integration tests
19-
will require a running MongoDB cluster with server versions 3.6.0 or later. The
20-
``{setFeatureCompatibilityVersion: 3.6}`` admin command will also need to have
21-
been executed to enable support for retryable writes on the cluster.
18+
Tests will require a MongoClient created with options defined in the tests.
19+
Integration tests will require a running MongoDB cluster with server versions
20+
3.6.0 or later. The ``{setFeatureCompatibilityVersion: 3.6}`` admin command
21+
will also need to have been executed to enable support for retryable writes on
22+
the cluster.
2223

2324
Server Fail Point
2425
=================
@@ -27,7 +28,9 @@ The tests depend on a server fail point, ``onPrimaryTransactionalWrite``, which
2728
allows us to force a network error before the server would return a write result
2829
to the client. The fail point also allows control whether the server will
2930
successfully commit the write via its ``failBeforeCommitExceptionCode`` option.
30-
The fail point is described in `SERVER-29606`_.
31+
Keep in mind that the fail point only triggers for transaction writes (i.e. write
32+
commands including ``txnNumber`` and ``lsid`` fields). See `SERVER-29606`_ for
33+
more information.
3134

3235
.. _SERVER-29606: https://jira.mongodb.org/browse/SERVER-29606
3336

@@ -135,15 +138,16 @@ Each YAML file has the following keys:
135138

136139
- ``description``: The name of the test.
137140

138-
- ``failPoint``: Document describing options for configuring the
139-
``onPrimaryTransactionalWrite`` fail point on the primary server. This
140-
document should be merged with the
141-
``{ configureFailPoint: "onPrimaryTransactionalWrite" }`` command document.
141+
- ``clientOptions``: Parameters to pass to MongoClient().
142+
143+
- ``failPoint``: The ``configureFailPoint`` command document to run to
144+
configure a fail point on the primary server. Drivers must ensure that
145+
``configureFailPoint`` is the first field in the command.
142146

143147
- ``operation``: Document describing the operation to be executed. The
144148
operation should be executed through a collection object derived from a
145-
driver session that has been created with the ``retryWrites=true`` option.
146-
This will have some or all of the following fields:
149+
client that has been created with ``clientOptions``. The operation will have
150+
some or all of the following fields:
147151

148152
- ``name``: The name of the operation as defined in the CRUD specification.
149153

tests/MongoDB.Driver.Tests.Dotnet/Specifications/retryable-writes/tests/bulkWrite.json

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"tests": [
1010
{
1111
"description": "First command is retried",
12+
"clientOptions": {
13+
"retryWrites": true
14+
},
1215
"failPoint": {
16+
"configureFailPoint": "onPrimaryTransactionalWrite",
1317
"mode": {
1418
"times": 1
1519
}
@@ -77,7 +81,11 @@
7781
},
7882
{
7983
"description": "All commands are retried",
84+
"clientOptions": {
85+
"retryWrites": true
86+
},
8087
"failPoint": {
88+
"configureFailPoint": "onPrimaryTransactionalWrite",
8189
"mode": {
8290
"times": 7
8391
}
@@ -206,7 +214,11 @@
206214
},
207215
{
208216
"description": "Both commands are retried after their first statement fails",
217+
"clientOptions": {
218+
"retryWrites": true
219+
},
209220
"failPoint": {
221+
"configureFailPoint": "onPrimaryTransactionalWrite",
210222
"mode": {
211223
"times": 2
212224
}
@@ -283,7 +295,11 @@
283295
},
284296
{
285297
"description": "Second command is retried after its second statement fails",
298+
"clientOptions": {
299+
"retryWrites": true
300+
},
286301
"failPoint": {
302+
"configureFailPoint": "onPrimaryTransactionalWrite",
287303
"mode": {
288304
"skip": 2
289305
}
@@ -360,7 +376,11 @@
360376
},
361377
{
362378
"description": "BulkWrite with unordered execution",
379+
"clientOptions": {
380+
"retryWrites": true
381+
},
363382
"failPoint": {
383+
"configureFailPoint": "onPrimaryTransactionalWrite",
364384
"mode": {
365385
"times": 1
366386
}
@@ -425,7 +445,11 @@
425445
},
426446
{
427447
"description": "First insertOne is never committed",
448+
"clientOptions": {
449+
"retryWrites": true
450+
},
428451
"failPoint": {
452+
"configureFailPoint": "onPrimaryTransactionalWrite",
429453
"mode": {
430454
"times": 2
431455
},
@@ -495,7 +519,11 @@
495519
},
496520
{
497521
"description": "Second updateOne is never committed",
522+
"clientOptions": {
523+
"retryWrites": true
524+
},
498525
"failPoint": {
526+
"configureFailPoint": "onPrimaryTransactionalWrite",
499527
"mode": {
500528
"skip": 1
501529
},
@@ -571,7 +599,11 @@
571599
},
572600
{
573601
"description": "Third updateOne is never committed",
602+
"clientOptions": {
603+
"retryWrites": true
604+
},
574605
"failPoint": {
606+
"configureFailPoint": "onPrimaryTransactionalWrite",
575607
"mode": {
576608
"skip": 2
577609
},
@@ -629,7 +661,140 @@
629661
"result": {
630662
"deletedCount": 0,
631663
"insertedIds": {
632-
"0": 2
664+
"1": 2
665+
},
666+
"matchedCount": 1,
667+
"modifiedCount": 1,
668+
"upsertedCount": 0,
669+
"upsertedIds": {}
670+
},
671+
"collection": {
672+
"data": [
673+
{
674+
"_id": 1,
675+
"x": 12
676+
},
677+
{
678+
"_id": 2,
679+
"x": 22
680+
}
681+
]
682+
}
683+
}
684+
},
685+
{
686+
"description": "Single-document write following deleteMany is retried",
687+
"clientOptions": {
688+
"retryWrites": true
689+
},
690+
"failPoint": {
691+
"configureFailPoint": "onPrimaryTransactionalWrite",
692+
"mode": {
693+
"times": 1
694+
},
695+
"data": {
696+
"failBeforeCommitExceptionCode": 1
697+
}
698+
},
699+
"operation": {
700+
"name": "bulkWrite",
701+
"arguments": {
702+
"requests": [
703+
{
704+
"name": "deleteMany",
705+
"arguments": {
706+
"filter": {
707+
"x": 11
708+
}
709+
}
710+
},
711+
{
712+
"name": "insertOne",
713+
"arguments": {
714+
"document": {
715+
"_id": 2,
716+
"x": 22
717+
}
718+
}
719+
}
720+
],
721+
"options": {
722+
"ordered": true
723+
}
724+
}
725+
},
726+
"outcome": {
727+
"result": {
728+
"deletedCount": 1,
729+
"insertedIds": {
730+
"1": 2
731+
},
732+
"matchedCount": 0,
733+
"modifiedCount": 0,
734+
"upsertedCount": 0,
735+
"upsertedIds": {}
736+
},
737+
"collection": {
738+
"data": [
739+
{
740+
"_id": 2,
741+
"x": 22
742+
}
743+
]
744+
}
745+
}
746+
},
747+
{
748+
"description": "Single-document write following updateMany is retried",
749+
"clientOptions": {
750+
"retryWrites": true
751+
},
752+
"failPoint": {
753+
"configureFailPoint": "onPrimaryTransactionalWrite",
754+
"mode": {
755+
"times": 1
756+
},
757+
"data": {
758+
"failBeforeCommitExceptionCode": 1
759+
}
760+
},
761+
"operation": {
762+
"name": "bulkWrite",
763+
"arguments": {
764+
"requests": [
765+
{
766+
"name": "updateMany",
767+
"arguments": {
768+
"filter": {
769+
"x": 11
770+
},
771+
"update": {
772+
"$inc": {
773+
"x": 1
774+
}
775+
}
776+
}
777+
},
778+
{
779+
"name": "insertOne",
780+
"arguments": {
781+
"document": {
782+
"_id": 2,
783+
"x": 22
784+
}
785+
}
786+
}
787+
],
788+
"options": {
789+
"ordered": true
790+
}
791+
}
792+
},
793+
"outcome": {
794+
"result": {
795+
"deletedCount": 0,
796+
"insertedIds": {
797+
"1": 2
633798
},
634799
"matchedCount": 1,
635800
"modifiedCount": 1,

0 commit comments

Comments
 (0)