6
6
use MongoDB \Database ;
7
7
use MongoDB \Driver \Cursor ;
8
8
use MongoDB \Driver \Session ;
9
+ use MongoDB \Driver \WriteConcern ;
9
10
use MongoDB \Driver \Exception \BulkWriteException ;
10
11
use MongoDB \Driver \Exception \Exception ;
11
12
use MongoDB \Operation \FindOneAndReplace ;
@@ -53,6 +54,11 @@ public static function fromChangeStreams(stdClass $operation)
53
54
{
54
55
$ o = new self ($ operation );
55
56
57
+ /* Note: change streams only return majority-committed writes, so ensure
58
+ * each operation applies that write concern. This will avoid spurious
59
+ * test failures. */
60
+ $ writeConcern = new WriteConcern (WriteConcern::MAJORITY );
61
+
56
62
// Expect all operations to succeed
57
63
$ o ->errorExpectation = ErrorExpectation::noError ();
58
64
@@ -66,13 +72,16 @@ public static function fromChangeStreams(stdClass $operation)
66
72
$ o ->arguments = ['command ' => [
67
73
'renameCollection ' => $ operation ->database . '. ' . $ operation ->collection ,
68
74
'to ' => $ operation ->database . '. ' . $ operation ->arguments ->to ,
75
+ // Note: Database::command() does not inherit WC, so be explicit
76
+ 'writeConcern ' => $ writeConcern ,
69
77
]];
70
78
71
79
return $ o ;
72
80
}
73
81
74
82
$ o ->databaseName = $ operation ->database ;
75
83
$ o ->collectionName = $ operation ->collection ;
84
+ $ o ->collectionOptions = ['writeConcern ' => $ writeConcern ];
76
85
$ o ->object = self ::OBJECT_SELECT_COLLECTION ;
77
86
78
87
return $ o ;
0 commit comments