Skip to content

Commit 9074847

Browse files
committed
Merge pull request #663
2 parents 703401d + 870024e commit 9074847

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

tests/FunctionalTestCase.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ protected function assertSameObjectId($expectedObjectId, $actualObjectId)
138138
*/
139139
protected function configureFailPoint($command)
140140
{
141+
if (! $this->isFailCommandSupported()) {
142+
$this->markTestSkipped('failCommand is only supported on mongod >= 4.0.0 and mongos >= 4.1.5.');
143+
}
144+
145+
if (! $this->isFailCommandEnabled()) {
146+
$this->markTestSkipped('The enableTestCommands parameter is not enabled.');
147+
}
148+
141149
if (is_array($command)) {
142150
$command = (object) $command;
143151
}
@@ -394,4 +402,37 @@ private function disableFailPoints()
394402
$operation->execute($server);
395403
}
396404
}
405+
406+
/**
407+
* Checks if the failCommand command is supported on this server version
408+
*
409+
* @return bool
410+
*/
411+
private function isFailCommandSupported()
412+
{
413+
$minVersion = $this->isShardedCluster() ? '4.1.5' : '4.0.0';
414+
415+
return version_compare($this->getServerVersion(), $minVersion, '>=');
416+
}
417+
418+
/**
419+
* Checks if the failCommand command is enabled by checking the enableTestCommands parameter
420+
*
421+
* @return bool
422+
*/
423+
private function isFailCommandEnabled()
424+
{
425+
try {
426+
$cursor = $this->manager->executeCommand(
427+
'admin',
428+
new Command(['getParameter' => 1, 'enableTestCommands' => 1])
429+
);
430+
431+
$document = current($cursor->toArray());
432+
} catch (CommandException $e) {
433+
return false;
434+
}
435+
436+
return isset($document->enableTestCommands) && $document->enableTestCommands === true;
437+
}
397438
}

tests/Operation/WatchFunctionalTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,6 @@ public function testInitialCursorIsNotClosed()
689689
*/
690690
public function testNonResumableErrorCodes($errorCode)
691691
{
692-
if (version_compare($this->getServerVersion(), '4.0.0', '<')) {
693-
$this->markTestSkipped('failCommand is not supported');
694-
}
695-
696692
$this->configureFailPoint([
697693
'configureFailPoint' => 'failCommand',
698694
'mode' => ['times' => 1],

0 commit comments

Comments
 (0)