Skip to content

Commit

Permalink
Merge v1.20 into v1.x (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Sep 19, 2024
2 parents b27a61d + 7e2925a commit 150d4f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
6 changes: 3 additions & 3 deletions tests/Operation/WatchFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ public function testInitialCursorIsNotClosed(): void
* reports the cursor as alive. While the cursor ID is accessed through
* ChangeStream, we'll need to use reflection to access the internal
* Cursor and call isDead(). */
$this->assertNotEquals('0', (string) $changeStream->getCursorId());
$this->assertNotEquals('0', (string) $changeStream->getCursorId(true));

$rc = new ReflectionClass(ChangeStream::class);
$rp = $rc->getProperty('iterator');
Expand Down Expand Up @@ -1370,11 +1370,11 @@ public function testOriginalReadPreferenceIsPreservedOnResume(): void
}

$changeStream = $operation->execute($secondary);
$previousCursorId = $changeStream->getCursorId();
$previousCursorId = $changeStream->getCursorId(true);
$this->forceChangeStreamResume();

$changeStream->next();
$this->assertNotSame($previousCursorId, $changeStream->getCursorId());
$this->assertNotSame($previousCursorId, $changeStream->getCursorId(true));

$getCursor = Closure::bind(
fn () => $this->iterator->getInnerIterator(),
Expand Down
14 changes: 7 additions & 7 deletions tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use MongoDB\Driver\Server;
use MongoDB\Tests\SpecTests\FunctionalTestCase;

use function assert;
Expand Down Expand Up @@ -65,7 +64,8 @@ public function testRetryOnDifferentMongos(): void

// Step 4: Enable failed command event monitoring for client
$subscriber = new class implements CommandSubscriber {
public $commandFailedServers = [];
/** @var int[] */
public array $commandFailedServers = [];

public function commandStarted(CommandStartedEvent $event): void
{
Expand All @@ -77,7 +77,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void

public function commandFailed(CommandFailedEvent $event): void
{
$this->commandFailedServers[] = $event->getServer();
$this->commandFailedServers[] = $event->getServerConnectionId();
}
};

Expand Down Expand Up @@ -130,21 +130,21 @@ public function testRetryOnSameMongos(): void

// Step 4: Enable succeeded and failed command event monitoring
$subscriber = new class implements CommandSubscriber {
public Server $commandSucceededServer;
public Server $commandFailedServer;
public ?int $commandSucceededServer = null;
public ?int $commandFailedServer = null;

public function commandStarted(CommandStartedEvent $event): void
{
}

public function commandSucceeded(CommandSucceededEvent $event): void
{
$this->commandSucceededServer = $event->getServer();
$this->commandSucceededServer = $event->getServerConnectionId();
}

public function commandFailed(CommandFailedEvent $event): void
{
$this->commandFailedServer = $event->getServer();
$this->commandFailedServer = $event->getServerConnectionId();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public function testRetryOnDifferentMongos(): void

// Step 4: Enable failed command event monitoring for client
$subscriber = new class implements CommandSubscriber {
public $commandFailedServers = [];
/** @var int[] */
public array $commandFailedServers = [];

public function commandStarted(CommandStartedEvent $event): void
{
Expand All @@ -79,7 +80,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void

public function commandFailed(CommandFailedEvent $event): void
{
$this->commandFailedServers[] = $event->getServer();
$this->commandFailedServers[] = $event->getServerConnectionId();
}
};

Expand Down
11 changes: 5 additions & 6 deletions tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use MongoDB\Driver\Server;
use MongoDB\Tests\SpecTests\FunctionalTestCase;

/**
Expand Down Expand Up @@ -50,21 +49,21 @@ public function testRetryOnSameMongos(): void

// Step 4: Enable succeeded and failed command event monitoring
$subscriber = new class implements CommandSubscriber {
public Server $commandSucceededServer;
public Server $commandFailedServer;
public ?int $commandSucceededServer = null;
public ?int $commandFailedServer = null;

public function commandStarted(CommandStartedEvent $event): void
{
}

public function commandSucceeded(CommandSucceededEvent $event): void
{
$this->commandSucceededServer = $event->getServer();
$this->commandSucceededServer = $event->getServerConnectionId();
}

public function commandFailed(CommandFailedEvent $event): void
{
$this->commandFailedServer = $event->getServer();
$this->commandFailedServer = $event->getServerConnectionId();
}
};

Expand All @@ -78,7 +77,7 @@ public function commandFailed(CommandFailedEvent $event): void

/* Step 6: Assert that exactly one failed command event and one
* succeeded command event occurred. Assert that both events occurred on
* the same mongos. */
* the same mongos connection. */
$this->assertNotNull($subscriber->commandSucceededServer);
$this->assertNotNull($subscriber->commandFailedServer);
$this->assertEquals($subscriber->commandSucceededServer, $subscriber->commandFailedServer);
Expand Down
10 changes: 1 addition & 9 deletions tests/UnifiedSpecTests/EventCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use function PHPUnit\Framework\assertIsObject;
use function PHPUnit\Framework\assertIsString;
use function PHPUnit\Framework\assertNotEmpty;
use function sprintf;

/**
* EventCollector handles "storeEventsAsEntities" for client entities.
Expand Down Expand Up @@ -108,7 +107,7 @@ private function handleCommandMonitoringEvent(CommandStartedEvent|CommandSucceed
'name' => self::getEventName($event),
'observedAt' => microtime(true),
'commandName' => $event->getCommandName(),
'connectionId' => self::getConnectionId($event),
'connectionId' => $event->getServerConnectionId(),
'requestId' => $event->getRequestId(),
'operationId' => $event->getOperationId(),
];
Expand All @@ -132,13 +131,6 @@ private function handleCommandMonitoringEvent(CommandStartedEvent|CommandSucceed
$this->eventList[] = $log;
}

private static function getConnectionId(CommandStartedEvent|CommandSucceededEvent|CommandFailedEvent $event): string
{
$server = $event->getServer();

return sprintf('%s:%d', $server->getHost(), $server->getPort());
}

private static function getEventName(object $event): string
{
static $eventNamesByClass = null;
Expand Down

0 comments on commit 150d4f1

Please sign in to comment.