Skip to content

Commit 6793cce

Browse files
committed
Update rename tests for sharded cluster
1 parent 796fae3 commit 6793cce

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,19 @@ public function testRenameToSameDatabase(): void
352352

353353
public function testRenameToDifferentDatabase(): void
354354
{
355+
$toDatabaseName = $this->getDatabaseName() . '_renamed';
356+
$toDatabase = new Database($this->manager, $toDatabaseName);
357+
358+
/* When renaming an unsharded collection, mongos requires the source
359+
* and target database to both exist on the primary shard. In practice, this
360+
* means we need to create the target database explicitly.
361+
* See: https://docs.mongodb.com/manual/reference/command/renameCollection/#unsharded-collections
362+
*/
355363
if ($this->isShardedCluster()) {
356-
$this->markTestSkipped('TODO: mongos requires the target database to exist');
364+
$toDatabase->foo->insertOne(['_id' => 1]);
357365
}
358366

359-
$toDatabaseName = $this->getDatabaseName() . '_renamed';
360367
$toCollectionName = $this->getCollectionName() . '.renamed';
361-
$toDatabase = new Database($this->manager, $toDatabaseName);
362368
$toCollection = new Collection($this->manager, $toDatabaseName, $toCollectionName);
363369

364370
$writeResult = $this->collection->insertOne(['_id' => 1]);

tests/Database/DatabaseFunctionalTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,19 @@ public function testRenameCollectionToSameDatabase(): void
239239

240240
public function testRenameCollectionToDifferentDatabase(): void
241241
{
242+
$toDatabaseName = $this->getDatabaseName() . '_renamed';
243+
$toDatabase = new Database($this->manager, $toDatabaseName);
244+
245+
/* When renaming an unsharded collection, mongos requires the source
246+
* and target database to both exist on the primary shard. In practice, this
247+
* means we need to create the target database explicitly.
248+
* See: https://docs.mongodb.com/manual/reference/command/renameCollection/#unsharded-collections
249+
*/
242250
if ($this->isShardedCluster()) {
243-
$this->markTestSkipped('TODO: mongos requires the target database to exist');
251+
$toDatabase->foo->insertOne(['_id' => 1]);
244252
}
245253

246-
$toDatabaseName = $this->getDatabaseName() . '_renamed';
247254
$toCollectionName = $this->getCollectionName() . '.renamed';
248-
$toDatabase = new Database($this->manager, $toDatabaseName);
249255
$toCollection = new Collection($this->manager, $toDatabaseName, $toCollectionName);
250256

251257
$bulkWrite = new BulkWrite();

0 commit comments

Comments
 (0)