Commit a949df52 authored by Derick Rethans's avatar Derick Rethans

PHPLIB-384: Allow ModifyCollection test to work in sharded environment

parent 75cbc782
...@@ -161,12 +161,30 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -161,12 +161,30 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$createIndexes = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes); $createIndexes = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);
$createIndexes->execute($this->getPrimaryServer()); $createIndexes->execute($this->getPrimaryServer());
$commandResult = $this->database->modifyCollection($this->getCollectionName(), ['index' => ['keyPattern' => ['lastAccess' => 1], 'expireAfterSeconds' => 1000]]); $commandResult = $this->database->modifyCollection(
$this->getCollectionName(),
['index' => ['keyPattern' => ['lastAccess' => 1], 'expireAfterSeconds' => 1000]],
['typeMap' => ['root' => 'array', 'document' => 'array']]
);
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$commandResult = (array) $commandResult;
if (array_key_exists('raw', $commandResult)) {
/* Sharded environment, where we only assert if a shard had a successful update. For
* non-primary shards that don't have chunks for the collection, the result contains a
* "ns does not exist" error. */
foreach ($commandResult['raw'] as $shard) {
if (array_key_exists('ok', $shard) && $shard['ok'] == 1) {
$this->assertSame(3, $shard['expireAfterSeconds_old']);
$this->assertSame(1000, $shard['expireAfterSeconds_new']);
}
}
} else {
$this->assertSame(3, $commandResult['expireAfterSeconds_old']); $this->assertSame(3, $commandResult['expireAfterSeconds_old']);
$this->assertSame(1000, $commandResult['expireAfterSeconds_new']); $this->assertSame(1000, $commandResult['expireAfterSeconds_new']);
} }
}
public function testSelectCollectionInheritsOptions() public function testSelectCollectionInheritsOptions()
......
...@@ -25,7 +25,21 @@ class ModifyCollectionFunctionalTest extends FunctionalTestCase ...@@ -25,7 +25,21 @@ class ModifyCollectionFunctionalTest extends FunctionalTestCase
); );
$result = $modifyCollection->execute($this->getPrimaryServer()); $result = $modifyCollection->execute($this->getPrimaryServer());
if (array_key_exists('raw', $result)) {
/* Sharded environment, where we only assert if a shard had a successful update. For
* non-primary shards that don't have chunks for the collection, the result contains a
* "ns does not exist" error. */
foreach ($result['raw'] as $shard) {
$shard = (array) $shard;
if (array_key_exists('ok', $shard) && $shard['ok'] == 1) {
$this->assertSame(3, $shard['expireAfterSeconds_old']);
$this->assertSame(1000, $shard['expireAfterSeconds_new']);
}
}
} else {
$this->assertSame(3, $result['expireAfterSeconds_old']); $this->assertSame(3, $result['expireAfterSeconds_old']);
$this->assertSame(1000, $result['expireAfterSeconds_new']); $this->assertSame(1000, $result['expireAfterSeconds_new']);
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment