Commit 746c0f07 authored by Jeremy Mikola's avatar Jeremy Mikola

Use w:majority for operations in change stream tests

This will avoid spurious test failures due to timing and ensure that each acknowledged write is returned in the next change stream iteration.
parent 80cee6f6
...@@ -7,6 +7,7 @@ use MongoDB\BSON\TimestampInterface; ...@@ -7,6 +7,7 @@ use MongoDB\BSON\TimestampInterface;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\ConnectionTimeoutException; use MongoDB\Driver\Exception\ConnectionTimeoutException;
use MongoDB\Driver\Exception\LogicException; use MongoDB\Driver\Exception\LogicException;
use MongoDB\Exception\ResumeTokenException; use MongoDB\Exception\ResumeTokenException;
...@@ -1026,7 +1027,12 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -1026,7 +1027,12 @@ class WatchFunctionalTest extends FunctionalTestCase
private function insertDocument($document) private function insertDocument($document)
{ {
$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); $insertOne = new InsertOne(
$this->getDatabaseName(),
$this->getCollectionName(),
$document,
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
);
$writeResult = $insertOne->execute($this->getPrimaryServer()); $writeResult = $insertOne->execute($this->getPrimaryServer());
$this->assertEquals(1, $writeResult->getInsertedCount()); $this->assertEquals(1, $writeResult->getInsertedCount());
} }
......
...@@ -6,6 +6,7 @@ use MongoDB\Collection; ...@@ -6,6 +6,7 @@ use MongoDB\Collection;
use MongoDB\Database; use MongoDB\Database;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Session; use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\BulkWriteException; use MongoDB\Driver\Exception\BulkWriteException;
use MongoDB\Driver\Exception\Exception; use MongoDB\Driver\Exception\Exception;
use MongoDB\Operation\FindOneAndReplace; use MongoDB\Operation\FindOneAndReplace;
...@@ -53,6 +54,11 @@ final class Operation ...@@ -53,6 +54,11 @@ final class Operation
{ {
$o = new self($operation); $o = new self($operation);
/* Note: change streams only return majority-committed writes, so ensure
* each operation applies that write concern. This will avoid spurious
* test failures. */
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
// Expect all operations to succeed // Expect all operations to succeed
$o->errorExpectation = ErrorExpectation::noError(); $o->errorExpectation = ErrorExpectation::noError();
...@@ -66,6 +72,8 @@ final class Operation ...@@ -66,6 +72,8 @@ final class Operation
$o->arguments = ['command' => [ $o->arguments = ['command' => [
'renameCollection' => $operation->database . '.' . $operation->collection, 'renameCollection' => $operation->database . '.' . $operation->collection,
'to' => $operation->database . '.' . $operation->arguments->to, 'to' => $operation->database . '.' . $operation->arguments->to,
// Note: Database::command() does not inherit WC, so be explicit
'writeConcern' => $writeConcern,
]]; ]];
return $o; return $o;
...@@ -73,6 +81,7 @@ final class Operation ...@@ -73,6 +81,7 @@ final class Operation
$o->databaseName = $operation->database; $o->databaseName = $operation->database;
$o->collectionName = $operation->collection; $o->collectionName = $operation->collection;
$o->collectionOptions = ['writeConcern' => $writeConcern];
$o->object = self::OBJECT_SELECT_COLLECTION; $o->object = self::OBJECT_SELECT_COLLECTION;
return $o; return $o;
......
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