Skip to content

Commit fe4ff68

Browse files
committed
Merge pull request #725
2 parents 8060d72 + 8f7d7f8 commit fe4ff68

38 files changed

+2592
-287
lines changed

tests/SpecTests/Context.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ public static function fromRetryableWrites(stdClass $test, $databaseName, $colle
185185

186186
$clientOptions = isset($test->clientOptions) ? (array) $test->clientOptions : [];
187187

188-
// TODO: Remove this once retryWrites=true by default (see: PHPC-1324)
189-
$clientOptions['retryWrites'] = true;
190-
191188
if (isset($test->outcome->collection->name)) {
192189
$o->outcomeCollectionName = $test->outcome->collection->name;
193190
}

tests/SpecTests/ResultExpectation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function fromRetryableReads(stdClass $operation, $defaultAssertion
126126

127127
public static function fromRetryableWrites(stdClass $outcome, $defaultAssertionType)
128128
{
129-
if (property_exists($outcome, 'result')) {
129+
if (property_exists($outcome, 'result') && ! self::isErrorResult($outcome->result)) {
130130
$assertionType = $outcome->result === null ? self::ASSERT_NULL : $defaultAssertionType;
131131
$expectedValue = $outcome->result;
132132
} else {
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.3.1",
5+
"topology": [
6+
"replicaset",
7+
"sharded"
8+
]
9+
}
10+
],
11+
"data": [
12+
{
13+
"_id": 1,
14+
"x": 11
15+
},
16+
{
17+
"_id": 2,
18+
"x": 22
19+
}
20+
],
21+
"tests": [
22+
{
23+
"description": "BulkWrite succeeds with RetryableWriteError from server",
24+
"failPoint": {
25+
"configureFailPoint": "failCommand",
26+
"mode": {
27+
"times": 1
28+
},
29+
"data": {
30+
"failCommands": [
31+
"update"
32+
],
33+
"errorCode": 112,
34+
"errorLabels": [
35+
"RetryableWriteError"
36+
]
37+
}
38+
},
39+
"operation": {
40+
"name": "bulkWrite",
41+
"arguments": {
42+
"requests": [
43+
{
44+
"name": "deleteOne",
45+
"arguments": {
46+
"filter": {
47+
"_id": 1
48+
}
49+
}
50+
},
51+
{
52+
"name": "insertOne",
53+
"arguments": {
54+
"document": {
55+
"_id": 3,
56+
"x": 33
57+
}
58+
}
59+
},
60+
{
61+
"name": "updateOne",
62+
"arguments": {
63+
"filter": {
64+
"_id": 2
65+
},
66+
"update": {
67+
"$inc": {
68+
"x": 1
69+
}
70+
}
71+
}
72+
}
73+
],
74+
"options": {
75+
"ordered": true
76+
}
77+
}
78+
},
79+
"outcome": {
80+
"result": {
81+
"deletedCount": 1,
82+
"insertedCount": 1,
83+
"insertedIds": {
84+
"1": 3
85+
},
86+
"matchedCount": 1,
87+
"modifiedCount": 1,
88+
"upsertedCount": 0,
89+
"upsertedIds": {}
90+
},
91+
"collection": {
92+
"data": [
93+
{
94+
"_id": 2,
95+
"x": 23
96+
},
97+
{
98+
"_id": 3,
99+
"x": 33
100+
}
101+
]
102+
}
103+
}
104+
},
105+
{
106+
"description": "BulkWrite fails if server does not return RetryableWriteError",
107+
"failPoint": {
108+
"configureFailPoint": "failCommand",
109+
"mode": {
110+
"times": 1
111+
},
112+
"data": {
113+
"failCommands": [
114+
"update"
115+
],
116+
"errorCode": 11600,
117+
"errorLabels": []
118+
}
119+
},
120+
"operation": {
121+
"name": "bulkWrite",
122+
"arguments": {
123+
"requests": [
124+
{
125+
"name": "deleteOne",
126+
"arguments": {
127+
"filter": {
128+
"_id": 1
129+
}
130+
}
131+
},
132+
{
133+
"name": "insertOne",
134+
"arguments": {
135+
"document": {
136+
"_id": 3,
137+
"x": 33
138+
}
139+
}
140+
},
141+
{
142+
"name": "updateOne",
143+
"arguments": {
144+
"filter": {
145+
"_id": 2
146+
},
147+
"update": {
148+
"$inc": {
149+
"x": 1
150+
}
151+
}
152+
}
153+
}
154+
],
155+
"options": {
156+
"ordered": true
157+
}
158+
}
159+
},
160+
"outcome": {
161+
"error": true,
162+
"result": {
163+
"errorLabelsOmit": [
164+
"RetryableWriteError"
165+
]
166+
},
167+
"collection": {
168+
"data": [
169+
{
170+
"_id": 2,
171+
"x": 22
172+
},
173+
{
174+
"_id": 3,
175+
"x": 33
176+
}
177+
]
178+
}
179+
}
180+
}
181+
]
182+
}

tests/SpecTests/retryable-writes/bulkWrite-serverErrors.json

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"failCommands": [
3636
"update"
3737
],
38-
"errorCode": 189
38+
"errorCode": 189,
39+
"errorLabels": [
40+
"RetryableWriteError"
41+
]
3942
}
4043
},
4144
"operation": {
@@ -117,7 +120,10 @@
117120
],
118121
"writeConcernError": {
119122
"code": 91,
120-
"errmsg": "Replication is being shut down"
123+
"errmsg": "Replication is being shut down",
124+
"errorLabels": [
125+
"RetryableWriteError"
126+
]
121127
}
122128
}
123129
},
@@ -186,6 +192,81 @@
186192
]
187193
}
188194
}
195+
},
196+
{
197+
"description": "BulkWrite fails with a RetryableWriteError label after two connection failures",
198+
"failPoint": {
199+
"configureFailPoint": "failCommand",
200+
"mode": {
201+
"times": 2
202+
},
203+
"data": {
204+
"failCommands": [
205+
"update"
206+
],
207+
"closeConnection": true
208+
}
209+
},
210+
"operation": {
211+
"name": "bulkWrite",
212+
"arguments": {
213+
"requests": [
214+
{
215+
"name": "deleteOne",
216+
"arguments": {
217+
"filter": {
218+
"_id": 1
219+
}
220+
}
221+
},
222+
{
223+
"name": "insertOne",
224+
"arguments": {
225+
"document": {
226+
"_id": 3,
227+
"x": 33
228+
}
229+
}
230+
},
231+
{
232+
"name": "updateOne",
233+
"arguments": {
234+
"filter": {
235+
"_id": 2
236+
},
237+
"update": {
238+
"$inc": {
239+
"x": 1
240+
}
241+
}
242+
}
243+
}
244+
],
245+
"options": {
246+
"ordered": true
247+
}
248+
}
249+
},
250+
"outcome": {
251+
"error": true,
252+
"result": {
253+
"errorLabelsContain": [
254+
"RetryableWriteError"
255+
]
256+
},
257+
"collection": {
258+
"data": [
259+
{
260+
"_id": 2,
261+
"x": 22
262+
},
263+
{
264+
"_id": 3,
265+
"x": 33
266+
}
267+
]
268+
}
269+
}
189270
}
190271
]
191272
}

0 commit comments

Comments
 (0)