Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tests/UnifiedSpecTests/UnifiedTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function doTestCase(stdClass $test, string $schemaVersion, ?array $runOn
$context = $this->createContext();

if (isset($initialData)) {
$this->prepareInitialData($initialData, $context, $this->isAdvanceClusterTimeNeeded($test->operations));
$this->prepareInitialData($initialData, $context, $this->isAdvanceClusterTimeNeeded($test->operations, $createEntities));
}

/* If an EntityMap observer has been configured, assign the Context's
Expand Down Expand Up @@ -435,8 +435,12 @@ private function prepareInitialData(array $initialData, Context $context, bool $

/**
* Work around potential MigrationConflict errors on sharded clusters.
*
* Cluster time advancement is also needed for snapshot sessions, since initialData uses an internal client that
* does not gossip its cluster time to test entities. Without advancement, a snapshot session may establish its
* atClusterTime before the initial data is visible, causing snapshot reads to return no results.
*/
private function isAdvanceClusterTimeNeeded(array $operations): bool
private function isAdvanceClusterTimeNeeded(array $operations, ?array $createEntities = null): bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the nullable array is because we have tests without entities, in which case we get null? Would it make sense to normalise that to an empty array before we pass it around?

{
if (! in_array($this->getPrimaryServer()->getType(), [Server::TYPE_MONGOS, Server::TYPE_LOAD_BALANCER], true)) {
return false;
Comment thread
paulinevos marked this conversation as resolved.
Expand All @@ -450,6 +454,17 @@ private function isAdvanceClusterTimeNeeded(array $operations): bool
}
}

foreach ($createEntities ?? [] as $entity) {
$session = $entity->session ?? null;
if ($session === null) {
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a continue -- there could still be an entity with a snapshot session later in the list that might necessitate a cluster time advancement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason the test is still failing after this PR.

The createEntities array in snapshot-sessions.json starts with client, database, and collection entries before the session entries:

[{client: {id: "client0", ...}}, {database: {...}}, {collection: {...}}, {session: {snapshot: true}}, ...]

When the loop reaches the first entity ({client: {...}}), $entity->session is null (the entity has no session key), so it hits return false and exits immediately — never reaching the actual snapshot sessions.

This should be continue (as @alcaeus noted) so the loop keeps checking remaining entities.

}

if (($session->sessionOptions?->snapshot ?? false) === true) {
return true;
}
}

return false;
}

Expand Down
Loading