Skip to content

Commit f517df8

Browse files
authored
PHPLIB-694: Spec tests for snapshot sessions (#851)
* PHPLIB-694: Spec tests for snapshot sessions Syncs tests with mongodb/specifications@ac49353 * Bumps ext-mongodb requirement to 1.11-dev This is necessary to pull in changes from PHPC-1761 for testing snapshot sessions.
1 parent 0be1877 commit f517df8

8 files changed

+1833
-15
lines changed

.evergreen/config.yml

Lines changed: 13 additions & 13 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:
@@ -574,7 +574,7 @@ buildvariants:
574574
# Tests all PHP versions on all operating systems.
575575
# Only tests against latest MongoDB and ext-mongodb versions
576576
- matrix_name: "test-php-versions"
577-
matrix_spec: {"os-php7": "*", "php-versions": "*", "edge-versions": "latest-stable", "driver-versions": "latest-stable" }
577+
matrix_spec: {"os-php7": "*", "php-versions": "*", "edge-versions": "latest-stable", "driver-versions": "latest-dev" }
578578
exclude_spec:
579579
# rhel71-power8 fails due to not reaching pecl
580580
- { "os-php7": "rhel71-power8", "php-versions": "*", edge-versions: "*", "driver-versions": "*" }
@@ -600,7 +600,7 @@ buildvariants:
600600
# Only tests on Ubuntu 18.04, with latest stable PHP and driver versions
601601
# Tests against various topologies
602602
- matrix_name: "test-mongodb-versions"
603-
matrix_spec: {"os-php7": "rhel70-test", "php-edge-versions": "latest-stable", "versions": "*", "driver-versions": "latest-stable" }
603+
matrix_spec: {"os-php7": "rhel70-test", "php-edge-versions": "latest-stable", "versions": "*", "driver-versions": "latest-dev" }
604604
display_name: "MongoDB ${versions}, PHP ${php-edge-versions}, ${os-php7}, ext-mongodb ${driver-versions}"
605605
tasks:
606606
- name: "test-standalone"
@@ -611,22 +611,22 @@ buildvariants:
611611
# Enables --prefer-lowest for composer to test oldest dependencies against all server versions
612612
# TODO: driver-versions can be changed back to lowest-supported when that version is enabled in the axis
613613
- matrix_name: "test-dependencies"
614-
matrix_spec: { "dependencies": "lowest", "os-php7": "rhel70-test", "php-edge-versions": "oldest-supported", "versions": "*", "driver-versions": "latest-stable" }
614+
matrix_spec: { "dependencies": "lowest", "os-php7": "rhel70-test", "php-edge-versions": "oldest-supported", "versions": "*", "driver-versions": "latest-dev" }
615615
display_name: "Dependencies: ${dependencies}, MongoDB ${versions}, PHP ${php-edge-versions}, ${os-php7}, ext-mongodb ${driver-versions}"
616616
tasks:
617617
- name: "test-standalone"
618618
- name: "test-replica_set"
619619
- name: "test-sharded_cluster"
620620

621621
- matrix_name: "atlas-data-lake-test"
622-
matrix_spec: { "php-edge-versions": "latest-stable", "driver-versions": "latest-stable" }
622+
matrix_spec: { "php-edge-versions": "latest-stable", "driver-versions": "latest-dev" }
623623
display_name: "Atlas Data Lake test"
624624
run_on: rhel70
625625
tasks:
626626
- name: "test-atlas-data-lake"
627627

628628
- matrix_name: "test-versioned-api"
629-
matrix_spec: { "php-edge-versions": "latest-stable", "versions": ["5.0", "latest"], "driver-versions": "latest-stable" }
629+
matrix_spec: { "php-edge-versions": "latest-stable", "versions": ["5.0", "latest"], "driver-versions": "latest-dev" }
630630
display_name: "Versioned API - ${versions}"
631631
run_on: rhel70
632632
tasks:

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+
}

0 commit comments

Comments
 (0)