Skip to content

Commit 1de8c49

Browse files
committed
PHPLIB-694: Spec tests for snapshot sessions
Syncs tests with mongodb/specifications/pull/1046 Bumps ext-mongodb requirement to 1.11-dev to pull in other changes from PHPC-1761
1 parent 60bd25a commit 1de8c49

8 files changed

+1828
-10
lines changed

.evergreen/config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,14 @@ axes:
473473
# display_name: "1.10.0"
474474
# variables:
475475
# EXTENSION_VERSION: "1.10.0"
476-
- id: "latest-stable"
477-
display_name: "Latest Stable (1.10.x)"
478-
variables:
479-
EXTENSION_VERSION: "stable"
480-
- id: "upcoming-stable"
481-
display_name: "1.10-dev"
482-
variables:
483-
EXTENSION_BRANCH: "v1.10"
476+
# - id: "latest-stable"
477+
# display_name: "Latest Stable (1.10.x)"
478+
# variables:
479+
# EXTENSION_VERSION: "stable"
480+
# - id: "upcoming-stable"
481+
# display_name: "1.10-dev"
482+
# variables:
483+
# EXTENSION_BRANCH: "v1.10"
484484
- id: "latest-dev"
485485
display_name: "1.11-dev (master)"
486486
variables:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"php": "^7.1 || ^8.0",
1313
"ext-hash": "*",
1414
"ext-json": "*",
15-
"ext-mongodb": "^1.10.0",
15+
"ext-mongodb": "^1.11.0",
1616
"jean85/pretty-package-versions": "^1.2 || ^2.0.1",
1717
"symfony/polyfill-php80": "^1.19"
1818
},

tests/UnifiedSpecTests/Context.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private static function prepareBucketOptions(array $options): array
452452

453453
private static function prepareSessionOptions(array $options): array
454454
{
455-
Util::assertHasOnlyKeys($options, ['causalConsistency', 'defaultTransactionOptions']);
455+
Util::assertHasOnlyKeys($options, ['causalConsistency', 'defaultTransactionOptions', 'snapshot']);
456456

457457
if (array_key_exists('causalConsistency', $options)) {
458458
assertIsBool($options['causalConsistency']);
@@ -463,6 +463,10 @@ private static function prepareSessionOptions(array $options): array
463463
$options['defaultTransactionOptions'] = self::prepareDefaultTransactionOptions((array) $options['defaultTransactionOptions']);
464464
}
465465

466+
if (array_key_exists('snapshot', $options)) {
467+
assertIsBool($options['snapshot']);
468+
}
469+
466470
return $options;
467471
}
468472

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ public function provideGridFSTests()
136136
return $this->provideTests(__DIR__ . '/gridfs/*.json');
137137
}
138138

139+
/**
140+
* @dataProvider provideSessionsTests
141+
*/
142+
public function testSessions(UnifiedTestCase $test): void
143+
{
144+
self::$runner->run($test);
145+
}
146+
147+
public function provideSessionsTests()
148+
{
149+
return $this->provideTests(__DIR__ . '/sessions/*.json');
150+
}
151+
139152
/**
140153
* @dataProvider provideTransactionsTests
141154
*/
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"description": "snapshot-sessions-not-supported-client-error",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "3.6",
7+
"maxServerVersion": "4.4.99"
8+
}
9+
],
10+
"createEntities": [
11+
{
12+
"client": {
13+
"id": "client0",
14+
"observeEvents": [
15+
"commandStartedEvent",
16+
"commandFailedEvent"
17+
]
18+
}
19+
},
20+
{
21+
"database": {
22+
"id": "database0",
23+
"client": "client0",
24+
"databaseName": "database0"
25+
}
26+
},
27+
{
28+
"collection": {
29+
"id": "collection0",
30+
"database": "database0",
31+
"collectionName": "collection0"
32+
}
33+
},
34+
{
35+
"session": {
36+
"id": "session0",
37+
"client": "client0",
38+
"sessionOptions": {
39+
"snapshot": true
40+
}
41+
}
42+
}
43+
],
44+
"initialData": [
45+
{
46+
"collectionName": "collection0",
47+
"databaseName": "database0",
48+
"documents": [
49+
{
50+
"_id": 1,
51+
"x": 11
52+
}
53+
]
54+
}
55+
],
56+
"tests": [
57+
{
58+
"description": "Client error on find with snapshot",
59+
"operations": [
60+
{
61+
"name": "find",
62+
"object": "collection0",
63+
"arguments": {
64+
"session": "session0",
65+
"filter": {}
66+
},
67+
"expectError": {
68+
"isClientError": true,
69+
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
70+
}
71+
}
72+
],
73+
"expectEvents": [
74+
{
75+
"client": "client0",
76+
"events": []
77+
}
78+
]
79+
},
80+
{
81+
"description": "Client error on aggregate with snapshot",
82+
"operations": [
83+
{
84+
"name": "aggregate",
85+
"object": "collection0",
86+
"arguments": {
87+
"session": "session0",
88+
"pipeline": []
89+
},
90+
"expectError": {
91+
"isClientError": true,
92+
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
93+
}
94+
}
95+
],
96+
"expectEvents": [
97+
{
98+
"client": "client0",
99+
"events": []
100+
}
101+
]
102+
},
103+
{
104+
"description": "Client error on distinct with snapshot",
105+
"operations": [
106+
{
107+
"name": "distinct",
108+
"object": "collection0",
109+
"arguments": {
110+
"fieldName": "x",
111+
"filter": {},
112+
"session": "session0"
113+
},
114+
"expectError": {
115+
"isClientError": true,
116+
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
117+
}
118+
}
119+
],
120+
"expectEvents": [
121+
{
122+
"client": "client0",
123+
"events": []
124+
}
125+
]
126+
}
127+
]
128+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"description": "snapshot-sessions-not-supported-server-error",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "5.0",
7+
"topologies": [
8+
"single"
9+
]
10+
}
11+
],
12+
"createEntities": [
13+
{
14+
"client": {
15+
"id": "client0",
16+
"observeEvents": [
17+
"commandStartedEvent",
18+
"commandFailedEvent"
19+
]
20+
}
21+
},
22+
{
23+
"database": {
24+
"id": "database0",
25+
"client": "client0",
26+
"databaseName": "database0"
27+
}
28+
},
29+
{
30+
"collection": {
31+
"id": "collection0",
32+
"database": "database0",
33+
"collectionName": "collection0"
34+
}
35+
},
36+
{
37+
"session": {
38+
"id": "session0",
39+
"client": "client0",
40+
"sessionOptions": {
41+
"snapshot": true
42+
}
43+
}
44+
}
45+
],
46+
"initialData": [
47+
{
48+
"collectionName": "collection0",
49+
"databaseName": "database0",
50+
"documents": [
51+
{
52+
"_id": 1,
53+
"x": 11
54+
}
55+
]
56+
}
57+
],
58+
"tests": [
59+
{
60+
"description": "Server returns an error on find with snapshot",
61+
"operations": [
62+
{
63+
"name": "find",
64+
"object": "collection0",
65+
"arguments": {
66+
"session": "session0",
67+
"filter": {}
68+
},
69+
"expectError": {
70+
"isError": true,
71+
"isClientError": false
72+
}
73+
}
74+
],
75+
"expectEvents": [
76+
{
77+
"client": "client0",
78+
"events": [
79+
{
80+
"commandStartedEvent": {
81+
"command": {
82+
"find": "collection0",
83+
"readConcern": {
84+
"level": "snapshot",
85+
"atClusterTime": {
86+
"$$exists": false
87+
}
88+
}
89+
}
90+
}
91+
},
92+
{
93+
"commandFailedEvent": {
94+
"commandName": "find"
95+
}
96+
}
97+
]
98+
}
99+
]
100+
},
101+
{
102+
"description": "Server returns an error on aggregate with snapshot",
103+
"operations": [
104+
{
105+
"name": "aggregate",
106+
"object": "collection0",
107+
"arguments": {
108+
"session": "session0",
109+
"pipeline": []
110+
},
111+
"expectError": {
112+
"isError": true,
113+
"isClientError": false
114+
}
115+
}
116+
],
117+
"expectEvents": [
118+
{
119+
"client": "client0",
120+
"events": [
121+
{
122+
"commandStartedEvent": {
123+
"command": {
124+
"aggregate": "collection0",
125+
"readConcern": {
126+
"level": "snapshot",
127+
"atClusterTime": {
128+
"$$exists": false
129+
}
130+
}
131+
}
132+
}
133+
},
134+
{
135+
"commandFailedEvent": {
136+
"commandName": "aggregate"
137+
}
138+
}
139+
]
140+
}
141+
]
142+
},
143+
{
144+
"description": "Server returns an error on distinct with snapshot",
145+
"operations": [
146+
{
147+
"name": "distinct",
148+
"object": "collection0",
149+
"arguments": {
150+
"fieldName": "x",
151+
"filter": {},
152+
"session": "session0"
153+
},
154+
"expectError": {
155+
"isError": true,
156+
"isClientError": false
157+
}
158+
}
159+
],
160+
"expectEvents": [
161+
{
162+
"client": "client0",
163+
"events": [
164+
{
165+
"commandStartedEvent": {
166+
"command": {
167+
"distinct": "collection0",
168+
"readConcern": {
169+
"level": "snapshot",
170+
"atClusterTime": {
171+
"$$exists": false
172+
}
173+
}
174+
}
175+
}
176+
},
177+
{
178+
"commandFailedEvent": {
179+
"commandName": "distinct"
180+
}
181+
}
182+
]
183+
}
184+
]
185+
}
186+
]
187+
}

0 commit comments

Comments
 (0)