SERVER-110393: Change prepare_transaction_survives_state_transition_to_and_from_recovering.js to use sameMembers instead of eq (#40992)

GitOrigin-RevId: c3bc4205fa43f011c9fc2352684ff90e523a908e
This commit is contained in:
Ruchitha Rajaghatta 2025-09-08 16:45:18 -04:00 committed by MongoDB Bot
parent 90a49aa8e1
commit 5219e05d1f

View File

@ -31,35 +31,35 @@ const session2 = primary.startSession({causalConsistency: false});
const sessionDB2 = session2.getDatabase(dbName);
const sessionColl2 = sessionDB2.getCollection(collName);
jsTestLog("Starting a transaction and putting it into prepare");
jsTest.log.info("Starting a transaction and putting it into prepare");
session1.startTransaction();
assert.commandWorked(sessionColl1.update({_id: 1}, {_id: 1, a: 1}));
const prepareTimestamp1 = PrepareHelpers.prepareTransaction(session1);
jsTestLog("Starting a second transaction and putting it into prepare");
jsTest.log.info("Starting a second transaction and putting it into prepare");
session2.startTransaction();
assert.commandWorked(sessionColl2.insert({_id: 2}));
const prepareTimestamp2 = PrepareHelpers.prepareTransaction(session2);
replSet.awaitReplication();
jsTestLog("Putting secondary in maintenance mode so it will transition to RECOVERING");
jsTest.log.info("Putting secondary in maintenance mode so it will transition to RECOVERING");
assert.commandWorked(secondary.adminCommand({replSetMaintenance: 1}));
replSet.waitForState(secondary, ReplSetTest.State.RECOVERING);
jsTestLog("Commiting the second prepared transaction while a node is in the RECOVERING state");
jsTest.log.info("Committing the second prepared transaction while a node is in the RECOVERING state");
assert.commandWorked(PrepareHelpers.commitTransaction(session2, prepareTimestamp2));
replSet.awaitReplication();
jsTestLog("Taking secondary out of maintenance mode so it will transition back to SECONDARY");
jsTest.log.info("Taking secondary out of maintenance mode so it will transition back to SECONDARY");
assert.commandWorked(secondary.adminCommand({replSetMaintenance: 0}));
replSet.awaitSecondaryNodes(null, [secondary]);
jsTestLog("Stepping up the secondary");
jsTest.log.info("Stepping up the secondary");
replSet.stepUp(secondary);
replSet.waitForState(secondary, ReplSetTest.State.PRIMARY);
@ -69,11 +69,11 @@ const newPrimaryDB = newPrimary.getDB(dbName);
// Create a proxy session to reuse the session state of the old primary.
const newSession = new _DelegatingDriverSession(newPrimary, session1);
jsTestLog("Make sure that the transaction is properly prepared");
jsTest.log.info("Make sure that the transaction is properly prepared");
// Make sure that we can't read changes to the document from the second transaction after
// recovery.
assert.eq(newPrimaryDB.getCollection(collName).find().toArray(), [{_id: 1}, {_id: 2}]);
assert.sameMembers(newPrimaryDB.getCollection(collName).find().toArray(), [{_id: 1}, {_id: 2}]);
// Make sure that another write on the same document from the second transaction causes a write
// conflict.
@ -88,14 +88,14 @@ assert.commandFailedWithCode(
ErrorCodes.PreparedTransactionInProgress,
);
jsTestLog("Verify that the locks from the prepared transaction are still held");
jsTest.log.info("Verify that the locks from the prepared transaction are still held");
assert.commandFailedWithCode(
newPrimaryDB.runCommand({drop: collName, maxTimeMS: 5 * 1000}),
ErrorCodes.MaxTimeMSExpired,
);
jsTestLog("Committing transaction");
jsTest.log.info("Committing transaction");
assert.commandWorked(PrepareHelpers.commitTransaction(newSession, prepareTimestamp1));
replSet.awaitReplication();