4646#include " mongo/db/jsobj.h"
4747#include " mongo/db/query/internal_plans.h"
4848#include " mongo/db/repl/bgsync.h"
49+ #include " mongo/db/repl/drop_pending_collection_reaper.h"
4950#include " mongo/db/repl/oplog.h"
5051#include " mongo/db/repl/oplog_interface_local.h"
5152#include " mongo/db/repl/replication_consistency_markers_mock.h"
@@ -120,6 +121,8 @@ void SyncTailTest::setUp() {
120121 const NamespaceString&,
121122 const std::vector<BSONObj>&) { return Status::OK (); };
122123 StorageInterface::set (service, std::move (storageInterface));
124+ DropPendingCollectionReaper::set (
125+ service, stdx::make_unique<DropPendingCollectionReaper>(_storageInterface));
123126
124127 _replicationProcess = new ReplicationProcess (
125128 _storageInterface, stdx::make_unique<ReplicationConsistencyMarkersMock>());
@@ -139,10 +142,12 @@ void SyncTailTest::setUp() {
139142}
140143
141144void SyncTailTest::tearDown () {
145+ auto service = getServiceContext ();
142146 _opCtx.reset ();
147+ ReplicationProcess::set (service, {});
148+ DropPendingCollectionReaper::set (service, {});
149+ StorageInterface::set (service, {});
143150 ServiceContextMongoDTest::tearDown ();
144- _storageInterface = nullptr ;
145- ReplicationProcess::set (getServiceContext (), {});
146151}
147152
148153SyncTailWithLocalDocumentFetcher::SyncTailWithLocalDocumentFetcher (const BSONObj& document)
@@ -1315,57 +1320,70 @@ TEST_F(IdempotencyTest, TextIndexDocumentHasUnknownLanguage) {
13151320}
13161321
13171322TEST_F (IdempotencyTest, CreateCollectionWithValidation) {
1318- getGlobalReplicationCoordinator ()->setFollowerMode (MemberState::RS_RECOVERING);
1319- auto options1 = fromjson (" {'validator' : {'phone' : {'$type' : 'string' } } }" );
1320- auto createColl1 = makeCreateCollectionOplogEntry (nextOpTime (), nss, options1);
1321- auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1322- auto options2 = fromjson (" {'validator' : {'phone' : {'$type' : 'number' } } }" );
1323- auto createColl2 = makeCreateCollectionOplogEntry (nextOpTime (), nss, options2);
1323+ ReplicationCoordinator::get (_opCtx.get ())->setFollowerMode (MemberState::RS_RECOVERING);
13241324
1325- auto ops = {createColl1, dropColl, createColl2};
1325+ auto runOpsAndValidate = [this ]() {
1326+ auto options1 = fromjson (" {'validator' : {'phone' : {'$type' : 'string' } } }" );
1327+ auto createColl1 = makeCreateCollectionOplogEntry (nextOpTime (), nss, options1);
1328+ auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1329+ auto options2 = fromjson (" {'validator' : {'phone' : {'$type' : 'number' } } }" );
1330+ auto createColl2 = makeCreateCollectionOplogEntry (nextOpTime (), nss, options2);
13261331
1327- ASSERT_OK (runOps (ops));
1328- auto hash = validate ();
1329- ASSERT_OK (runOps (ops));
1330- ASSERT_EQUALS (hash, validate ());
1332+ auto ops = {createColl1, dropColl, createColl2};
1333+
1334+ ASSERT_OK (runOps (ops));
1335+ auto hash = validate ();
1336+
1337+ return hash;
1338+ };
1339+
1340+ auto hash1 = runOpsAndValidate ();
1341+ auto hash2 = runOpsAndValidate ();
1342+ ASSERT_EQUALS (hash1, hash2);
13311343}
13321344
13331345TEST_F (IdempotencyTest, CreateCollectionWithCollation) {
13341346 getGlobalReplicationCoordinator ()->setFollowerMode (MemberState::RS_RECOVERING);
13351347 ASSERT_OK (runOp (createCollection ()));
13361348
1337- auto insertOp1 = insert (fromjson (" { _id: 'foo' }" ));
1338- auto insertOp2 = insert (fromjson (" { _id: 'Foo', x: 1 }" ));
1339- auto updateOp = update (" foo" , BSON (" $set" << BSON (" x" << 2 )));
1340- auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1341- auto options = BSON (" collation" << BSON (" locale"
1342- << " en"
1343- << " caseLevel"
1344- << false
1345- << " caseFirst"
1346- << " off"
1347- << " strength"
1348- << 1
1349- << " numericOrdering"
1350- << false
1351- << " alternate"
1352- << " non-ignorable"
1353- << " maxVariable"
1354- << " punct"
1355- << " normalization"
1356- << false
1357- << " backwards"
1358- << false
1359- << " version"
1360- << " 57.1" ));
1361- auto createColl = makeCreateCollectionOplogEntry (nextOpTime (), nss, options);
1362-
1363- auto ops = {insertOp1, insertOp2, updateOp, dropColl, createColl};
1349+ auto runOpsAndValidate = [this ]() {
1350+ auto insertOp1 = insert (fromjson (" { _id: 'foo' }" ));
1351+ auto insertOp2 = insert (fromjson (" { _id: 'Foo', x: 1 }" ));
1352+ auto updateOp = update (" foo" , BSON (" $set" << BSON (" x" << 2 )));
1353+ auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1354+ auto options = BSON (" collation" << BSON (" locale"
1355+ << " en"
1356+ << " caseLevel"
1357+ << false
1358+ << " caseFirst"
1359+ << " off"
1360+ << " strength"
1361+ << 1
1362+ << " numericOrdering"
1363+ << false
1364+ << " alternate"
1365+ << " non-ignorable"
1366+ << " maxVariable"
1367+ << " punct"
1368+ << " normalization"
1369+ << false
1370+ << " backwards"
1371+ << false
1372+ << " version"
1373+ << " 57.1" ));
1374+ auto createColl = makeCreateCollectionOplogEntry (nextOpTime (), nss, options);
1375+
1376+ auto ops = {insertOp1, insertOp2, updateOp, dropColl, createColl};
1377+
1378+ ASSERT_OK (runOps (ops));
1379+ auto hash = validate ();
1380+
1381+ return hash;
1382+ };
13641383
1365- ASSERT_OK (runOps (ops));
1366- auto hash = validate ();
1367- ASSERT_OK (runOps (ops));
1368- ASSERT_EQUALS (hash, validate ());
1384+ auto hash1 = runOpsAndValidate ();
1385+ auto hash2 = runOpsAndValidate ();
1386+ ASSERT_EQUALS (hash1, hash2);
13691387}
13701388
13711389TEST_F (IdempotencyTest, CreateCollectionWithIdIndex) {
@@ -1380,16 +1398,22 @@ TEST_F(IdempotencyTest, CreateCollectionWithIdIndex) {
13801398 auto createColl1 = makeCreateCollectionOplogEntry (nextOpTime (), nss, options1);
13811399 ASSERT_OK (runOp (createColl1));
13821400
1383- auto insertOp = insert (BSON (" _id" << Decimal128 (1 )));
1384- auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1385- auto createColl2 = createCollection ();
1401+ auto runOpsAndValidate = [this ]() {
1402+ auto insertOp = insert (BSON (" _id" << Decimal128 (1 )));
1403+ auto dropColl = makeCommandOplogEntry (nextOpTime (), nss, BSON (" drop" << nss.coll ()));
1404+ auto createColl2 = createCollection ();
13861405
1387- auto ops = {insertOp, dropColl, createColl2};
1406+ auto ops = {insertOp, dropColl, createColl2};
13881407
1389- ASSERT_OK (runOps (ops));
1390- auto hash = validate ();
1391- ASSERT_OK (runOps (ops));
1392- ASSERT_EQUALS (hash, validate ());
1408+ ASSERT_OK (runOps (ops));
1409+ auto hash = validate ();
1410+
1411+ return hash;
1412+ };
1413+
1414+ auto hash1 = runOpsAndValidate ();
1415+ auto hash2 = runOpsAndValidate ();
1416+ ASSERT_EQUALS (hash1, hash2);
13931417}
13941418
13951419TEST_F (IdempotencyTest, CreateCollectionWithView) {
0 commit comments