-
Notifications
You must be signed in to change notification settings - Fork 263
Fix flaky session test #1895
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
base: v2.x
Are you sure you want to change the base?
Fix flaky session test #1895
Changes from all commits
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 |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| { | ||
| if (! in_array($this->getPrimaryServer()->getType(), [Server::TYPE_MONGOS, Server::TYPE_LOAD_BALANCER], true)) { | ||
| return false; | ||
|
paulinevos marked this conversation as resolved.
|
||
|
|
@@ -450,6 +454,17 @@ private function isAdvanceClusterTimeNeeded(array $operations): bool | |
| } | ||
| } | ||
|
|
||
| foreach ($createEntities ?? [] as $entity) { | ||
| $session = $entity->session ?? null; | ||
| if ($session === null) { | ||
| return false; | ||
|
Member
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 should be a
Member
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 is the reason the test is still failing after this PR. The When the loop reaches the first entity ( This should be |
||
| } | ||
|
|
||
| if (($session->sessionOptions?->snapshot ?? false) === true) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
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.
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?