Skip to content

Commit fca066e

Browse files
committed
PHPLIB-670: Unified test runner changes for serverless support
Sync unified transaction tests with mongodb/specifications@ba8a3f7 Detection of serverless will be addressed after driver support is implemented (PHPC-1755)
1 parent dd9ce1c commit fca066e

File tree

3 files changed

+112
-7
lines changed

3 files changed

+112
-7
lines changed

tests/UnifiedSpecTests/RunOnRequirement.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use stdClass;
77
use function array_diff;
88
use function in_array;
9+
use function PHPUnit\Framework\assertContains;
910
use function PHPUnit\Framework\assertContainsOnly;
1011
use function PHPUnit\Framework\assertEmpty;
1112
use function PHPUnit\Framework\assertIsArray;
@@ -22,6 +23,10 @@ class RunOnRequirement
2223
const TOPOLOGY_SHARDED_REPLICASET = 'sharded-replicaset';
2324
const TOPOLOGY_LOAD_BALANCED = 'load-balanced';
2425

26+
const SERVERLESS_REQUIRE = 'require';
27+
const SERVERLESS_FORBID = 'forbid';
28+
const SERVERLESS_ALLOW = 'allow';
29+
2530
const VERSION_PATTERN = '/^[0-9]+(\\.[0-9]+){1,2}$/';
2631

2732
/** @var string */
@@ -39,6 +44,9 @@ class RunOnRequirement
3944
/** @var bool */
4045
private $auth;
4146

47+
/** @var string */
48+
private $serverless;
49+
4250
/** @var array */
4351
private static $supportedTopologies = [
4452
self::TOPOLOGY_SINGLE,
@@ -48,9 +56,16 @@ class RunOnRequirement
4856
self::TOPOLOGY_LOAD_BALANCED,
4957
];
5058

59+
/** @var array */
60+
private static $supportedServerless = [
61+
self::SERVERLESS_REQUIRE,
62+
self::SERVERLESS_FORBID,
63+
self::SERVERLESS_ALLOW,
64+
];
65+
5166
public function __construct(stdClass $o)
5267
{
53-
Util::assertHasOnlyKeys($o, ['minServerVersion', 'maxServerVersion', 'topologies', 'serverParameters', 'auth']);
68+
Util::assertHasOnlyKeys($o, ['minServerVersion', 'maxServerVersion', 'topologies', 'serverParameters', 'auth', 'serverless']);
5469

5570
if (isset($o->minServerVersion)) {
5671
assertIsString($o->minServerVersion);
@@ -80,9 +95,15 @@ public function __construct(stdClass $o)
8095
assertIsBool($o->auth);
8196
$this->auth = $o->auth;
8297
}
98+
99+
if (isset($o->serverless)) {
100+
assertIsString($o->serverless);
101+
assertContains($o->serverless, self::$supportedServerless);
102+
$this->serverless = $o->serverless;
103+
}
83104
}
84105

85-
public function isSatisfied(string $serverVersion, string $topology, stdClass $serverParameters, bool $isAuthenticated) : bool
106+
public function isSatisfied(string $serverVersion, string $topology, stdClass $serverParameters, bool $isAuthenticated, bool $isServerless) : bool
86107
{
87108
if (isset($this->minServerVersion) && version_compare($serverVersion, $this->minServerVersion, '<')) {
88109
return false;
@@ -107,6 +128,16 @@ public function isSatisfied(string $serverVersion, string $topology, stdClass $s
107128
return false;
108129
}
109130

131+
if (isset($this->serverless)) {
132+
if (! $isServerless && $this->serverless === self::SERVERLESS_REQUIRE) {
133+
return false;
134+
}
135+
136+
if ($isServerless && $this->serverless === self::SERVERLESS_FORBID) {
137+
return false;
138+
}
139+
}
140+
110141
return true;
111142
}
112143

tests/UnifiedSpecTests/UnifiedTestRunner.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class UnifiedTestRunner
4545
const SERVER_ERROR_UNAUTHORIZED = 13;
4646

4747
const MIN_SCHEMA_VERSION = '1.0';
48-
const MAX_SCHEMA_VERSION = '1.3';
48+
const MAX_SCHEMA_VERSION = '1.4';
4949

5050
/** @var MongoDB\Client */
5151
private $internalClient;
@@ -232,6 +232,7 @@ private function checkRunOnRequirements(array $runOnRequirements)
232232
$this->getTopology(),
233233
$this->getServerParameters(),
234234
$this->isAuthenticated(),
235+
$this->isServerless(),
235236
];
236237
}
237238

@@ -329,6 +330,15 @@ private function isAuthenticated() : bool
329330
throw new UnexpectedValueException('Could not determine authentication status');
330331
}
331332

333+
/**
334+
* Return whether serverless (i.e. proxy as mongos) is being utilized.
335+
*/
336+
private function isServerless() : bool
337+
{
338+
// TODO: detect serverless once PHPC-1755 is implemented
339+
return false;
340+
}
341+
332342
/**
333343
* Checks is a test format schema version is supported.
334344
*/

tests/UnifiedSpecTests/transactions/mongos-unpin.json

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "mongos-unpin",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.2",
@@ -49,7 +49,12 @@
4949
},
5050
"tests": [
5151
{
52-
"description": "unpin after TransientTransctionError error on commit",
52+
"description": "unpin after TransientTransactionError error on commit",
53+
"runOnRequirements": [
54+
{
55+
"serverless": "forbid"
56+
}
57+
],
5358
"operations": [
5459
{
5560
"name": "startTransaction",
@@ -103,6 +108,24 @@
103108
"arguments": {
104109
"session": "session0"
105110
}
111+
},
112+
{
113+
"name": "startTransaction",
114+
"object": "session0"
115+
},
116+
{
117+
"name": "insertOne",
118+
"object": "collection0",
119+
"arguments": {
120+
"document": {
121+
"x": 1
122+
},
123+
"session": "session0"
124+
}
125+
},
126+
{
127+
"name": "abortTransaction",
128+
"object": "session0"
106129
}
107130
]
108131
},
@@ -137,7 +160,12 @@
137160
]
138161
},
139162
{
140-
"description": "unpin after TransientTransctionError error on abort",
163+
"description": "unpin after non-transient error on abort",
164+
"runOnRequirements": [
165+
{
166+
"serverless": "forbid"
167+
}
168+
],
141169
"operations": [
142170
{
143171
"name": "startTransaction",
@@ -182,11 +210,29 @@
182210
"arguments": {
183211
"session": "session0"
184212
}
213+
},
214+
{
215+
"name": "startTransaction",
216+
"object": "session0"
217+
},
218+
{
219+
"name": "insertOne",
220+
"object": "collection0",
221+
"arguments": {
222+
"document": {
223+
"x": 1
224+
},
225+
"session": "session0"
226+
}
227+
},
228+
{
229+
"name": "abortTransaction",
230+
"object": "session0"
185231
}
186232
]
187233
},
188234
{
189-
"description": "unpin after non-transient error on abort",
235+
"description": "unpin after TransientTransactionError error on abort",
190236
"operations": [
191237
{
192238
"name": "startTransaction",
@@ -231,6 +277,24 @@
231277
"arguments": {
232278
"session": "session0"
233279
}
280+
},
281+
{
282+
"name": "startTransaction",
283+
"object": "session0"
284+
},
285+
{
286+
"name": "insertOne",
287+
"object": "collection0",
288+
"arguments": {
289+
"document": {
290+
"x": 1
291+
},
292+
"session": "session0"
293+
}
294+
},
295+
{
296+
"name": "abortTransaction",
297+
"object": "session0"
234298
}
235299
]
236300
},

0 commit comments

Comments
 (0)