Skip to content

Commit c1b85e8

Browse files
committed
Catch exceptions, so that we can still test writeConcern with ping
1 parent d36784d commit c1b85e8

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

tests/manager/manager-executeRawCommand-001.phpt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ $manager = new MongoDB\Driver\Manager(STANDALONE);
1616
$command = new MongoDB\Driver\Command([
1717
'ping' => true,
1818
]);
19-
$manager->executeCommand(
20-
DATABASE_NAME,
21-
$command,
22-
[
23-
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY),
24-
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL),
25-
/* The ping command itself doesn't support writeConcern */
26-
// 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
27-
]
28-
);
19+
20+
try {
21+
$manager->executeCommand(
22+
DATABASE_NAME,
23+
$command,
24+
[
25+
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY),
26+
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL),
27+
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
28+
]
29+
);
30+
} catch ( Exception $e ) {
31+
// Ignore exception that ping doesn't support writeConcern
32+
}
2933
},
3034
function(stdClass $command) {
3135
echo "Read Preference: ", $command->{'$readPreference'}->mode, "\n";
3236
echo "Read Concern: ", $command->readConcern->level, "\n";
33-
// echo "Write Concern: ", $command->writeConcern->w, "\n";
37+
echo "Write Concern: ", $command->writeConcern->w, "\n";
3438
}
3539
);
3640

@@ -40,4 +44,5 @@ $manager = new MongoDB\Driver\Manager(STANDALONE);
4044
--EXPECTF--
4145
Read Preference: secondary
4246
Read Concern: local
47+
Write Concern: majority
4348
===DONE===

tests/utils/observer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ public function observe(callable $execution, callable $commandCallback)
1313
{
1414
$this->commands = [];
1515
\MongoDB\Driver\Monitoring\addSubscriber($this);
16-
call_user_func($execution);
17-
\MongoDB\Driver\Monitoring\removeSubscriber($this);
18-
foreach ($this->commands as $command) {
19-
call_user_func($commandCallback, $command);
16+
try {
17+
call_user_func($execution);
18+
} finally {
19+
\MongoDB\Driver\Monitoring\removeSubscriber($this);
20+
foreach ($this->commands as $command) {
21+
call_user_func($commandCallback, $command);
22+
}
2023
}
2124
}
2225
public function commandStarted(CommandStartedEvent $event)

0 commit comments

Comments
 (0)