Skip to content

Commit c029a86

Browse files
committed
Support new serverParameters runOnRequirement in unified test runner
1 parent 2c80b35 commit c029a86

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

tests/FunctionalTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ protected function getPrimaryServer()
267267
return $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
268268
}
269269

270+
protected function getServerParameters()
271+
{
272+
$cursor = $this->manager->executeCommand(
273+
'admin',
274+
new Command(['getParameter' => '*']),
275+
new ReadPreference(ReadPreference::RP_PRIMARY)
276+
);
277+
278+
$cursor->rewind();
279+
280+
return $cursor->current();
281+
}
282+
270283
protected function getServerVersion(ReadPreference $readPreference = null)
271284
{
272285
$cursor = $this->manager->executeCommand(

tests/UnifiedSpecTests/RunOnRequirement.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace MongoDB\Tests\UnifiedSpecTests;
44

5+
use MongoDB\Tests\UnifiedSpecTests\Constraint\Matches;
56
use stdClass;
67
use function in_array;
78
use function PHPUnit\Framework\assertContainsOnly;
89
use function PHPUnit\Framework\assertIsArray;
10+
use function PHPUnit\Framework\assertIsObject;
911
use function PHPUnit\Framework\assertIsString;
1012
use function PHPUnit\Framework\assertMatchesRegularExpression;
1113
use function version_compare;
@@ -28,6 +30,9 @@ class RunOnRequirement
2830
/** @var array */
2931
private $topologies;
3032

33+
/** @var stdClass */
34+
private $serverParameters;
35+
3136
public function __construct(stdClass $o)
3237
{
3338
if (isset($o->minServerVersion)) {
@@ -47,9 +52,14 @@ public function __construct(stdClass $o)
4752
assertContainsOnly('string', $o->topologies);
4853
$this->topologies = $o->topologies;
4954
}
55+
56+
if (isset($o->serverParameters)) {
57+
assertIsObject($o->serverParameters);
58+
$this->serverParameters = $o->serverParameters;
59+
}
5060
}
5161

52-
public function isSatisfied(string $serverVersion, string $topology) : bool
62+
public function isSatisfied(string $serverVersion, string $topology, stdClass $serverParameters) : bool
5363
{
5464
if (isset($this->minServerVersion) && version_compare($serverVersion, $this->minServerVersion, '<')) {
5565
return false;
@@ -73,6 +83,13 @@ public function isSatisfied(string $serverVersion, string $topology) : bool
7383
return false;
7484
}
7585

86+
if (isset($this->serverParameters)) {
87+
$constraint = new Matches($this->serverParameters, null, true, false);
88+
if (! $constraint->evaluate($serverParameters, '', true)) {
89+
return false;
90+
}
91+
}
92+
7693
return true;
7794
}
7895
}

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UnifiedSpecTest extends FunctionalTestCase
3333
const SERVER_ERROR_INTERRUPTED = 11601;
3434

3535
const MIN_SCHEMA_VERSION = '1.0';
36-
const MAX_SCHEMA_VERSION = '1.1';
36+
const MAX_SCHEMA_VERSION = '1.2';
3737

3838
const TOPOLOGY_SINGLE = 'single';
3939
const TOPOLOGY_REPLICASET = 'replicaset';
@@ -252,17 +252,35 @@ private function checkRunOnRequirements(array $runOnRequirements)
252252

253253
$serverVersion = $this->getCachedServerVersion();
254254
$topology = $this->getCachedTopology();
255+
$serverParameters = $this->getCachedServerParameters();
255256

256257
foreach ($runOnRequirements as $o) {
257258
$runOnRequirement = new RunOnRequirement($o);
258-
if ($runOnRequirement->isSatisfied($serverVersion, $topology)) {
259+
if ($runOnRequirement->isSatisfied($serverVersion, $topology, $serverParameters)) {
259260
return;
260261
}
261262
}
262263

264+
// @todo Add server parameter requirements?
263265
$this->markTestSkipped(sprintf('Server version "%s" and topology "%s" do not meet test requirements', $serverVersion, $topology));
264266
}
265267

268+
/**
269+
* Return the server parameters (cached for subsequent calls).
270+
*/
271+
private function getCachedServerParameters()
272+
{
273+
static $cachedServerParameters;
274+
275+
if (isset($cachedServerParameters)) {
276+
return $cachedServerParameters;
277+
}
278+
279+
$cachedServerParameters = $this->getServerParameters();
280+
281+
return $cachedServerParameters;
282+
}
283+
266284
/**
267285
* Return the server version (cached for subsequent calls).
268286
*

0 commit comments

Comments
 (0)