/**
* Tests that even if dropping a drop-pending collection namespaces fails that it is eventually
* retried and dropped.
*/
(function() {
"use strict";
load("jstests/libs/check_log.js");
const rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const primaryDB = primary.getDB("test");
assert.commandWorked(primary.getDB("test1").runCommand({create: "to_be_dropped1"}));
assert.commandWorked(primary.getDB("test1").runCommand({create: "other_collection"}));
assert.commandWorked(primary.getDB("test2").runCommand({create: "to_be_dropped2"}));
assert.commandWorked(primary.adminCommand(
{configureFailPoint: "dropPendingCollectionReaperHang", mode: "alwaysOn"}));
assert.commandWorked(primary.getDB("test1").runCommand({drop: "to_be_dropped1"}));
assert.commandWorked(primary.adminCommand(
{configureFailPoint: "failNonIntentLocksIfWaitNeeded", mode: "alwaysOn"}));
const session = primary.startSession({causalConsistency: false});
const sessionDB = session.getDatabase("test1");
session.startTransaction();
assert.commandWorked(sessionDB.other_collection.insert({}));
assert.commandWorked(
primary.adminCommand({configureFailPoint: "dropPendingCollectionReaperHang", mode: "off"}));
checkLog.contains(primary, "Failed to remove drop-pending collection test1.system.drop");
session.abortTransaction();
assert.commandWorked(
primary.adminCommand({configureFailPoint: "failNonIntentLocksIfWaitNeeded", mode: "off"}));
assert.commandWorked(primary.getDB("test2").runCommand({drop: "to_be_dropped2"}));
checkLog.contains(primary, "Finishing collection drop for test2.system.drop");
let collInfos = primary.getDB("test2")
.runCommand({listCollections: 1, includePendingDrops: true})
.cursor.firstBatch;
assert.eq([], collInfos);
collInfos = primary.getDB("test1")
.runCommand({listCollections: 1, includePendingDrops: true})
.cursor.firstBatch;
assert.eq([], collInfos.filter(collInfo => collInfo.name !== "other_collection"));
rst.stopSet();
})();