Skip to content

Commit

Permalink
Harden explain tests (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus authored Nov 13, 2023
1 parent a5657d7 commit 46a0eda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions tests/Operation/AggregateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ public function testExplainOption(): void
$this->assertCount(1, $results);

$checkResult = $results[0];

// Sharded clusters and load balanced servers list plans per shard
if (array_key_exists('shards', $results[0])) {
$firstShard = array_key_first((array) $results[0]['shards']);
$checkResult = (array) $results[0]['shards']->$firstShard;
if (array_key_exists('shards', $checkResult)) {
$firstShard = array_key_first((array) $checkResult['shards']);
$checkResult = (array) $checkResult['shards']->$firstShard;
}

/* MongoDB 4.2 may optimize aggregate pipelines into queries, which can
Expand Down
13 changes: 6 additions & 7 deletions tests/Operation/ExplainFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function testAggregate(): void
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['verbosity' => Explain::VERBOSITY_QUERY, 'typeMap' => ['root' => 'array', 'document' => 'array']]);
$result = $explainOperation->execute($this->getPrimaryServer());

$this->assertExplainResult($result, false, false, true);
$this->assertExplainResult($result, false, false);
}

/** @dataProvider provideVerbosityInformation */
Expand Down Expand Up @@ -369,7 +369,7 @@ public function provideVerbosityInformation()
];
}

private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected, $stagesExpected = false): void
private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected): void
{
$checkResult = $result;

Expand All @@ -378,11 +378,10 @@ private function assertExplainResult($result, $executionStatsExpected, $allPlans
$checkResult = $result['shards'][$firstShard];
}

if ($stagesExpected) {
$this->assertArrayHasKey('stages', $checkResult);
} else {
$this->assertArrayHasKey('queryPlanner', $checkResult);
}
$this->assertThat($checkResult, $this->logicalOr(
$this->arrayHasKey('stages'),
$this->arrayHasKey('queryPlanner'),
));

if ($executionStatsExpected) {
$this->assertArrayHasKey('executionStats', $checkResult);
Expand Down

0 comments on commit 46a0eda

Please sign in to comment.