-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CursorId
and Event::getServer()
deprecation in tests
#1423
Changes from all commits
c6f9f00
8c0ff42
6364173
e3a370d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
{ | ||
|
@@ -77,7 +77,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void | |
|
||
public function commandFailed(CommandFailedEvent $event): void | ||
{ | ||
$this->commandFailedServers[] = $event->getServer(); | ||
$this->commandFailedServers[] = $event->getServerConnectionId(); | ||
} | ||
}; | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This relates the following assertion: /* Step 6: Assert that exactly one failed command event and one
* succeeded command event occurred. Assert that both events occurred on
* the same mongos. */ Those rely on |
||
|
||
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(); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,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. | ||
|
@@ -120,7 +119,7 @@ private function handleCommandMonitoringEvent($event): void | |
'name' => self::getEventName($event), | ||
'observedAt' => microtime(true), | ||
'commandName' => $event->getCommandName(), | ||
'connectionId' => self::getConnectionId($event), | ||
'connectionId' => $event->getServerConnectionId(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logs and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quoting the Workload Executor Specification from drivers-atlas-testing:
The only other field here that corresponds to an existing field in the Unified Test Format spec's expectedEvent section is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: #1428 |
||
'requestId' => $event->getRequestId(), | ||
'operationId' => $event->getOperationId(), | ||
]; | ||
|
@@ -144,14 +143,6 @@ private function handleCommandMonitoringEvent($event): void | |
$this->eventList[] = $log; | ||
} | ||
|
||
/** @param CommandStartedEvent|CommandSucceededEvent|CommandFailedEvent $event */ | ||
private static function getConnectionId($event): string | ||
{ | ||
$server = $event->getServer(); | ||
|
||
return sprintf('%s:%d', $server->getHost(), $server->getPort()); | ||
} | ||
|
||
private static function getEventName(object $event): string | ||
{ | ||
static $eventNamesByClass = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later, this was used for the following assertion:
Per
getServerConnectionId()
, the connection ID is unique within the context of a single server. It is also only reported by MongoDB 4.2+. I think the correct change here would have been to replacegetServer()
with a concatenation of the server host/port. I'll make the change in a subsequent PR.As-is, I think this might sometimes fail if both mongoses reported the same connection ID or if we test on mongos 4.0.