Skip to content

Commit

Permalink
PHPC-1878 and PHPC-2008: Fix tests using local database (#1277)
Browse files Browse the repository at this point in the history
* PHPC-1878: Explicitly use w:1 for local database

* PHPC-2008: Skip test requiring role to drop local collection

The "restore" role is required to drop collections in the "local" database. Mongo Orchestration does not yet grant that role for its users.
  • Loading branch information
jmikola committed Nov 30, 2021
1 parent d32a44a commit 36f6ce0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tests/replicaset/manager-selectserver-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ MongoDB\Driver\Manager::selectServer() select a server from SDAM based on ReadPr
require_once __DIR__ . "/../utils/basic.inc";

// Disable retryWrites since the test writes to the unreplicated "local" database
$manager = create_test_manager(URI, ['retryWrites' => false]);
// Explicitly use w:1 to work around MongoDB 5.0 applying w:majority (SERVER-61790)
$manager = create_test_manager(URI, ['retryWrites' => false, 'w' => 1]);

$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
$server = $manager->selectServer($rp);
Expand Down
7 changes: 5 additions & 2 deletions tests/replicaset/writeresult-getserver-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MongoDB\Driver\Server: Manager->getServer() returning correct server
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_auth(); /* TODO: PHPC-2008 */ ?>
<?php skip_if_not_replica_set(); ?>
<?php skip_if_no_secondary(); ?>
<?php skip_if_not_clean(); ?>
Expand All @@ -11,8 +12,8 @@ MongoDB\Driver\Server: Manager->getServer() returning correct server
require_once __DIR__ . "/../utils/basic.inc";

// Disable retryWrites since the test writes to the unreplicated "local" database
$manager = create_test_manager(URI, ['retryWrites' => false]);

// Explicitly use w:1 to work around MongoDB 5.0 applying w:majority (SERVER-61790)
$manager = create_test_manager(URI, ['retryWrites' => false, 'w' => 1]);

$doc = array("example" => "document");
$bulk = new \MongoDB\Driver\BulkWrite();
Expand Down Expand Up @@ -80,6 +81,8 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
NULL
["writeConcern"]=>
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(1)
}
}
string(%d) "%s"
Expand Down
3 changes: 2 additions & 1 deletion tests/server/server-executeBulkWrite-005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ MongoDB\Driver\Server::executeBulkWrite() with write concern (replica set second
require_once __DIR__ . "/../utils/basic.inc";

// Disable retryWrites since the test writes to the unreplicated "local" database
$manager = create_test_manager(URI, ['retryWrites' => false]);
// Explicitly use w:1 to work around MongoDB 5.0 applying w:majority (SERVER-61790)
$manager = create_test_manager(URI, ['retryWrites' => false, 'w' => 1]);
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY));

/* The server ignores write concerns with w>2 for writes to the local database,
Expand Down
15 changes: 9 additions & 6 deletions tests/utils/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ function drop_collection($uri, $databaseName, $collectionName)
$command = new Command(['drop' => $collectionName]);

try {
/* We need to use WriteConcern::MAJORITY here due to the issue
* explained in SERVER-35613: "drop" uses a two phase commit, and due
* to that, it is possible that a lock can't be acquired for a
* transaction that gets quickly started as the "drop" reaper hasn't
* completed yet. */
/* Unless we are dropping a collection within the "local" database,
* which does not support a write concern, we need to use w:majority due
* to the issue explained in SERVER-35613: "drop" uses a two phase
* commit, and due to that, it is possible that a lock can't be acquired
* for a transaction that gets quickly started as the "drop" reaper
* hasn't completed yet. */
$wc = $databaseName === 'local' ? new WriteConcern(1) : new WriteConcern(WriteConcern::MAJORITY);

$server->executeCommand(
$databaseName,
$command,
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
['writeConcern' => $wc]
);
} catch (RuntimeException $e) {
if ($e->getMessage() !== 'ns not found') {
Expand Down

0 comments on commit 36f6ce0

Please sign in to comment.