forked from mongodb/mongo-php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug1274-004.phpt
83 lines (66 loc) · 2.24 KB
/
bug1274-004.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--TEST--
PHPC-1274: Cursor destruct should not kill cursor from parent process (disableClientPersistence=true)
--SKIPIF--
<?php if (!function_exists('pcntl_fork')) { die('skip pcntl_fork() not available'); } ?>
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_live(); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
class CommandLogger implements MongoDB\Driver\Monitoring\CommandSubscriber
{
private $pid;
public function __construct()
{
$this->pid = getmypid();
}
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
{
$command = $event->getCommand();
$commandName = $event->getCommandName();
$process = $this->pid === getmypid() ? 'Parent' : 'Child';
if ($commandName === 'find' || $commandName === 'getMore') {
printf("%s executes %s with batchSize: %d\n", $process, $commandName, $command->batchSize);
return;
}
printf("%s executes %s\n", $process, $commandName);
}
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
{
}
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
{
}
}
$manager = create_test_manager(URI, [], ['disableClientPersistence' => true]);
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$bulk->insert(['x' => 3]);
$manager->executeBulkWrite(NS, $bulk);
MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger);
$query = new MongoDB\Driver\Query([], ['batchSize' => 2]);
$cursor = $manager->executeQuery(NS, $query);
$childPid = pcntl_fork();
if ($childPid === 0) {
echo "Child exits\n";
exit;
}
if ($childPid > 0) {
$waitPid = pcntl_waitpid($childPid, $status);
if ($waitPid === $childPid) {
echo "Parent waited for child to exit\n";
}
printf("Parent fully iterated cursor for %d documents\n", iterator_count($cursor));
}
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Parent executes find with batchSize: 2
Child exits
Parent waited for child to exit
Parent executes getMore with batchSize: 2
Parent fully iterated cursor for 3 documents
===DONE===