mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-03-25 17:32:28 +01:00
* Add missing macros for declaring arguments * Add macros to define disabled constructor and __wakeup * Define arginfo via stubs for BSON classes * Declare tentative return types in interfaces * Add correct return type for __set_state methods * Generate class entries for BSON classes * Declare Binary class constants in stub file * Use stubs in exception classes * Add stubs for monitoring classes * Fix wrong JsonSerializable class in BSON stubs * Disable declaration-after-statement This is necessary to let the generated arginfo files compile * Use stubs for driver classes * Fix deprecation messages in tests * Add missing macro * Fix tests relying on value injection * Parse parameters in disabled constructor/wakup function * Add note about arginfo files to contribution docs * Add GitHub action to check generated arginfo files * PHPC-2115: Use DateTimeInterface in UTCDateTime constructor signature * Don't install mongodb extension in GitHub actions workflows * Change indentation in stub files * Use individual #if conditions for each stub method * Make disabled constructor/wakeup methods static * Fix bulkWrite parameter name * Use %d to match property count in tests * Ensure all classes with disabled serialisation declare __wakeup
130 lines
4.6 KiB
PHP
130 lines
4.6 KiB
PHP
--TEST--
|
|
PHPC-1152: Command cursors should use the same session for getMore and killCursors (explicit)
|
|
--SKIPIF--
|
|
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
|
|
<?php skip_if_not_libmongoc_crypto(); ?>
|
|
<?php skip_if_not_live(); ?>
|
|
<?php skip_if_not_clean(); ?>
|
|
--FILE--
|
|
<?php
|
|
require_once __DIR__ . "/../utils/basic.inc";
|
|
|
|
class Test implements MongoDB\Driver\Monitoring\CommandSubscriber
|
|
{
|
|
private $lsidByCursorId = [];
|
|
private $lsidByRequestId = [];
|
|
|
|
public function executeCommand()
|
|
{
|
|
$manager = create_test_manager();
|
|
|
|
$bulk = new MongoDB\Driver\BulkWrite;
|
|
$bulk->insert(['_id' => 1]);
|
|
$bulk->insert(['_id' => 2]);
|
|
$bulk->insert(['_id' => 3]);
|
|
$manager->executeBulkWrite(NS, $bulk);
|
|
|
|
$command = new MongoDB\Driver\Command([
|
|
'aggregate' => COLLECTION_NAME,
|
|
'pipeline' => [['$match' => new stdClass]],
|
|
'cursor' => ['batchSize' => 2],
|
|
]);
|
|
|
|
$session = $manager->startSession();
|
|
|
|
MongoDB\Driver\Monitoring\addSubscriber($this);
|
|
|
|
/* This uses the same sequencing as the implicit session test; however,
|
|
* we should expect all commands (aggregate, getMore, and killCursors)
|
|
* to use the same explicit session ID. */
|
|
$cursor = $manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
|
|
$cursor->toArray();
|
|
|
|
$cursor = $manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
|
|
$cursor->toArray();
|
|
|
|
$cursor = $manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
|
|
$cursor = $manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
|
|
unset($cursor);
|
|
|
|
MongoDB\Driver\Monitoring\removeSubscriber($this);
|
|
|
|
/* We should expect one unique session ID over the course of the test,
|
|
* since all commands used the same explicit session. */
|
|
printf("Unique session IDs used: %d\n", count(array_unique($this->lsidByRequestId)));
|
|
}
|
|
|
|
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
|
|
{
|
|
$requestId = $event->getRequestId();
|
|
$sessionId = bin2hex((string) $event->getCommand()->lsid->id);
|
|
|
|
printf("%s session ID: %s\n", $event->getCommandName(), $sessionId);
|
|
|
|
if ($event->getCommandName() === 'aggregate') {
|
|
if (isset($this->lsidByRequestId[$requestId])) {
|
|
throw new UnexpectedValueException('Previous command observed for request ID: ' . $requestId);
|
|
}
|
|
|
|
$this->lsidByRequestId[$requestId] = $sessionId;
|
|
}
|
|
|
|
if ($event->getCommandName() === 'getMore') {
|
|
$cursorId = (string) $event->getCommand()->getMore;
|
|
|
|
if ( ! isset($this->lsidByCursorId[$cursorId])) {
|
|
throw new UnexpectedValueException('No previous command observed for cursor ID: ' . $cursorId);
|
|
}
|
|
|
|
printf("getMore used same session as aggregate: %s\n", $sessionId === $this->lsidByCursorId[$cursorId] ? 'yes' : 'no');
|
|
}
|
|
|
|
if ($event->getCommandName() === 'killCursors') {
|
|
$cursorId = (string) $event->getCommand()->cursors[0];
|
|
|
|
if ( ! isset($this->lsidByCursorId[$cursorId])) {
|
|
throw new UnexpectedValueException('No previous command observed for cursor ID: ' . $cursorId);
|
|
}
|
|
|
|
printf("killCursors used same session as aggregate: %s\n", $sessionId === $this->lsidByCursorId[$cursorId] ? 'yes' : 'no');
|
|
}
|
|
}
|
|
|
|
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
|
|
{
|
|
/* Associate the aggregate's session ID with its cursor ID so it can be
|
|
* looked up by the subsequent getMore or killCursors */
|
|
if ($event->getCommandName() === 'aggregate') {
|
|
$cursorId = (string) $event->getReply()->cursor->id;
|
|
$requestId = $event->getRequestId();
|
|
|
|
$this->lsidByCursorId[$cursorId] = $this->lsidByRequestId[$requestId];
|
|
}
|
|
}
|
|
|
|
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
|
|
{
|
|
}
|
|
}
|
|
|
|
(new Test)->executeCommand();
|
|
|
|
?>
|
|
===DONE===
|
|
<?php exit(0); ?>
|
|
--EXPECTF--
|
|
aggregate session ID: %x
|
|
getMore session ID: %x
|
|
getMore used same session as aggregate: yes
|
|
aggregate session ID: %x
|
|
getMore session ID: %x
|
|
getMore used same session as aggregate: yes
|
|
aggregate session ID: %x
|
|
aggregate session ID: %x
|
|
killCursors session ID: %x
|
|
killCursors used same session as aggregate: yes
|
|
killCursors session ID: %x
|
|
killCursors used same session as aggregate: yes
|
|
Unique session IDs used: 1
|
|
===DONE===
|