Skip to content

Commit 9d7c442

Browse files
committed
Merge branch 'phplib-561' into v1.7
* phplib-561: PHPLIB-561: Retry replSetStepDown in connection failover test
2 parents b755292 + 819d403 commit 9d7c442

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/SpecTests/PrimaryStepDownSpecTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
1717
use UnexpectedValueException;
1818
use function current;
19+
use function sprintf;
1920

2021
/**
2122
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests
@@ -215,7 +216,20 @@ public function testGetMoreIteration()
215216

216217
// Send a {replSetStepDown: 5, force: true} command to the current primary and verify that the command succeeded
217218
$primary = $this->client->getManager()->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
218-
$primary->executeCommand('admin', new Command(['replSetStepDown' => 5, 'force' => true]));
219+
220+
$success = false;
221+
$attempts = 0;
222+
do {
223+
try {
224+
$attempts++;
225+
$primary->executeCommand('admin', new Command(['replSetStepDown' => 5, 'force' => true]));
226+
$success = true;
227+
} catch (DriverException $e) {
228+
if ($attempts == 10) {
229+
$this->fail(sprintf('Could not successfully execute replSetStepDown within %d attempts', $attempts));
230+
}
231+
}
232+
} while (! $success);
219233

220234
// Retrieve the next batch of results from the cursor obtained in the find operation, and verify that this operation succeeded.
221235
$events = [];

0 commit comments

Comments
 (0)