Skip to content

Commit d5ce656

Browse files
committed
Merge pull request #610
2 parents d444dde + 3715923 commit d5ce656

22 files changed

+4838
-0
lines changed

tests/SpecTests/FunctionalTestCase.php

Lines changed: 587 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\SpecTests;
4+
5+
/**
6+
* Retryable writes spec tests.
7+
*
8+
* @see https://github.com/mongodb/specifications/tree/master/source/retryable-writes
9+
*/
10+
class RetryableWritesSpecTest extends FunctionalTestCase
11+
{
12+
/**
13+
* Execute an individual test case from the specification.
14+
*
15+
* @dataProvider provideTests
16+
* @param string $name Test name
17+
* @param array $test Individual "tests[]" document
18+
* @param array $runOn Top-level "runOn" document
19+
* @param array $data Top-level "data" array to initialize collection
20+
*/
21+
public function testRetryableWrites($name, array $test, array $runOn = null, array $data)
22+
{
23+
$this->setName($name);
24+
25+
if (isset($runOn)) {
26+
$this->checkServerRequirements($runOn);
27+
}
28+
29+
// TODO: Remove this once retryWrites=true by default (see: PHPC-1324)
30+
$test['clientOptions']['retryWrites'] = true;
31+
32+
$this->initTestSubjects($test);
33+
$this->initOutcomeCollection($test);
34+
$this->initDataFixtures($data);
35+
36+
if (isset($test['failPoint'])) {
37+
$this->configureFailPoint($test['failPoint']);
38+
}
39+
40+
$this->assertOperation($test['operation'], $test['outcome']);
41+
42+
if (isset($test['outcome']['collection']['data'])) {
43+
$this->assertOutcomeCollectionData($test['outcome']['collection']['data']);
44+
}
45+
}
46+
47+
public function provideTests()
48+
{
49+
$testArgs = [];
50+
51+
foreach (glob(__DIR__ . '/retryable-writes/*.json') as $filename) {
52+
$json = json_decode(file_get_contents($filename), true);
53+
$group = basename($filename, '.json');
54+
$runOn = isset($json['runOn']) ? $json['runOn'] : null;
55+
$data = isset($json['data']) ? $json['data'] : [];
56+
57+
foreach ($json['tests'] as $test) {
58+
$name = $group . ': ' . $test['description'];
59+
$testArgs[] = [$name, $test, $runOn, $data];
60+
}
61+
}
62+
63+
return $testArgs;
64+
}
65+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.7",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
16+
"data": [
17+
{
18+
"_id": 1,
19+
"x": 11
20+
},
21+
{
22+
"_id": 2,
23+
"x": 22
24+
}
25+
],
26+
"tests": [
27+
{
28+
"description": "BulkWrite succeeds after PrimarySteppedDown",
29+
"failPoint": {
30+
"configureFailPoint": "failCommand",
31+
"mode": {
32+
"times": 1
33+
},
34+
"data": {
35+
"failCommands": [
36+
"update"
37+
],
38+
"errorCode": 189
39+
}
40+
},
41+
"operation": {
42+
"name": "bulkWrite",
43+
"arguments": {
44+
"requests": [
45+
{
46+
"name": "deleteOne",
47+
"arguments": {
48+
"filter": {
49+
"_id": 1
50+
}
51+
}
52+
},
53+
{
54+
"name": "insertOne",
55+
"arguments": {
56+
"document": {
57+
"_id": 3,
58+
"x": 33
59+
}
60+
}
61+
},
62+
{
63+
"name": "updateOne",
64+
"arguments": {
65+
"filter": {
66+
"_id": 2
67+
},
68+
"update": {
69+
"$inc": {
70+
"x": 1
71+
}
72+
}
73+
}
74+
}
75+
],
76+
"options": {
77+
"ordered": true
78+
}
79+
}
80+
},
81+
"outcome": {
82+
"result": {
83+
"deletedCount": 1,
84+
"insertedCount": 1,
85+
"insertedIds": {
86+
"1": 3
87+
},
88+
"matchedCount": 1,
89+
"modifiedCount": 1,
90+
"upsertedCount": 0,
91+
"upsertedIds": {}
92+
},
93+
"collection": {
94+
"data": [
95+
{
96+
"_id": 2,
97+
"x": 23
98+
},
99+
{
100+
"_id": 3,
101+
"x": 33
102+
}
103+
]
104+
}
105+
}
106+
},
107+
{
108+
"description": "BulkWrite succeeds after WriteConcernError ShutdownInProgress",
109+
"failPoint": {
110+
"configureFailPoint": "failCommand",
111+
"mode": {
112+
"times": 1
113+
},
114+
"data": {
115+
"failCommands": [
116+
"insert"
117+
],
118+
"writeConcernError": {
119+
"code": 91,
120+
"errmsg": "Replication is being shut down"
121+
}
122+
}
123+
},
124+
"operation": {
125+
"name": "bulkWrite",
126+
"arguments": {
127+
"requests": [
128+
{
129+
"name": "deleteOne",
130+
"arguments": {
131+
"filter": {
132+
"_id": 1
133+
}
134+
}
135+
},
136+
{
137+
"name": "insertOne",
138+
"arguments": {
139+
"document": {
140+
"_id": 3,
141+
"x": 33
142+
}
143+
}
144+
},
145+
{
146+
"name": "updateOne",
147+
"arguments": {
148+
"filter": {
149+
"_id": 2
150+
},
151+
"update": {
152+
"$inc": {
153+
"x": 1
154+
}
155+
}
156+
}
157+
}
158+
],
159+
"options": {
160+
"ordered": true
161+
}
162+
}
163+
},
164+
"outcome": {
165+
"result": {
166+
"deletedCount": 1,
167+
"insertedCount": 1,
168+
"insertedIds": {
169+
"1": 3
170+
},
171+
"matchedCount": 1,
172+
"modifiedCount": 1,
173+
"upsertedCount": 0,
174+
"upsertedIds": {}
175+
},
176+
"collection": {
177+
"data": [
178+
{
179+
"_id": 2,
180+
"x": 23
181+
},
182+
{
183+
"_id": 3,
184+
"x": 33
185+
}
186+
]
187+
}
188+
}
189+
}
190+
]
191+
}

0 commit comments

Comments
 (0)