Skip to content

Commit d32b161

Browse files
committed
PHPC-2030: Test observation of commands issued during client destruction
Command monitoring events can only be observed for non-persistent clients freed before RSHUTDOWN.
1 parent bbff147 commit d32b161

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
MongoDB\Driver\Monitoring\CommandStartedEvent during mongoc_client_destroy()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_not_live(); ?>
7+
<?php skip_if_server_version('<', '3.6'); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
13+
{
14+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
15+
{
16+
printf("Observed commandStarted for %s\n", $event->getCommandName());
17+
}
18+
19+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) {}
20+
21+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) {}
22+
}
23+
24+
$manager = create_test_manager(URI, [], ['disableClientPersistence' => true]);
25+
26+
$singleSubscriber = new MySubscriber();
27+
$manager->addSubscriber($singleSubscriber);
28+
29+
$command = new MongoDB\Driver\Command(['ping' => 1]);
30+
$manager->executeCommand(DATABASE_NAME, $command);
31+
32+
/* Events dispatched during mongoc_client_destroy can only be observed before
33+
* RSHUTDOWN. This means that we must use a non-persistent client and free it
34+
* before the script ends. */
35+
unset($manager);
36+
37+
?>
38+
===DONE===
39+
--EXPECT--
40+
Observed commandStarted for ping
41+
Observed commandStarted for endSessions
42+
===DONE===

0 commit comments

Comments
 (0)