Skip to content

Commit 36f6ce0

Browse files
authored
PHPC-1878 and PHPC-2008: Fix tests using local database (#1277)
* 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.
1 parent d32a44a commit 36f6ce0

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

tests/replicaset/manager-selectserver-001.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ MongoDB\Driver\Manager::selectServer() select a server from SDAM based on ReadPr
1010
require_once __DIR__ . "/../utils/basic.inc";
1111

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

1516
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
1617
$server = $manager->selectServer($rp);

tests/replicaset/writeresult-getserver-002.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MongoDB\Driver\Server: Manager->getServer() returning correct server
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_auth(); /* TODO: PHPC-2008 */ ?>
56
<?php skip_if_not_replica_set(); ?>
67
<?php skip_if_no_secondary(); ?>
78
<?php skip_if_not_clean(); ?>
@@ -11,8 +12,8 @@ MongoDB\Driver\Server: Manager->getServer() returning correct server
1112
require_once __DIR__ . "/../utils/basic.inc";
1213

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

1718
$doc = array("example" => "document");
1819
$bulk = new \MongoDB\Driver\BulkWrite();
@@ -80,6 +81,8 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
8081
NULL
8182
["writeConcern"]=>
8283
object(MongoDB\Driver\WriteConcern)#%d (%d) {
84+
["w"]=>
85+
int(1)
8386
}
8487
}
8588
string(%d) "%s"

tests/server/server-executeBulkWrite-005.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ MongoDB\Driver\Server::executeBulkWrite() with write concern (replica set second
1010
require_once __DIR__ . "/../utils/basic.inc";
1111

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

1617
/* The server ignores write concerns with w>2 for writes to the local database,

tests/utils/tools.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ function drop_collection($uri, $databaseName, $collectionName)
5151
$command = new Command(['drop' => $collectionName]);
5252

5353
try {
54-
/* We need to use WriteConcern::MAJORITY here due to the issue
55-
* explained in SERVER-35613: "drop" uses a two phase commit, and due
56-
* to that, it is possible that a lock can't be acquired for a
57-
* transaction that gets quickly started as the "drop" reaper hasn't
58-
* completed yet. */
54+
/* Unless we are dropping a collection within the "local" database,
55+
* which does not support a write concern, we need to use w:majority due
56+
* to the issue explained in SERVER-35613: "drop" uses a two phase
57+
* commit, and due to that, it is possible that a lock can't be acquired
58+
* for a transaction that gets quickly started as the "drop" reaper
59+
* hasn't completed yet. */
60+
$wc = $databaseName === 'local' ? new WriteConcern(1) : new WriteConcern(WriteConcern::MAJORITY);
61+
5962
$server->executeCommand(
6063
$databaseName,
6164
$command,
62-
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
65+
['writeConcern' => $wc]
6366
);
6467
} catch (RuntimeException $e) {
6568
if ($e->getMessage() !== 'ns not found') {

0 commit comments

Comments
 (0)