summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-04-04 13:47:34 -0400
committerBenety Goh <benety@mongodb.com>2018-04-04 13:47:34 -0400
commitc04aa22602fd1640758886b9945a987214f08c88 (patch)
tree14c3e5f1d8d35266d27b9dd3ff74db15e1b2e160 /jstests
parent4c42865f840749592ce16f4e0858b09522e6a74d (diff)
downloadmongo-c04aa22602fd1640758886b9945a987214f08c88.tar.gz
SERVER-33343 move test functions from transaction_table_oplog_reply.js to retryable_writes_util.js for reuse
Diffstat (limited to 'jstests')
-rw-r--r--jstests/libs/retryable_writes_util.js34
-rw-r--r--jstests/replsets/transaction_table_oplog_replay.js40
2 files changed, 41 insertions, 33 deletions
diff --git a/jstests/libs/retryable_writes_util.js b/jstests/libs/retryable_writes_util.js
index 5105157eba1..6c5c244045f 100644
--- a/jstests/libs/retryable_writes_util.js
+++ b/jstests/libs/retryable_writes_util.js
@@ -30,5 +30,37 @@ var RetryableWritesUtil = (function() {
return !kStorageEnginesWithoutDocumentLocking.has(storageEngineName);
}
- return {isRetryableCode, isRetryableWriteCmdName, storageEngineSupportsRetryableWrites};
+ /**
+ * Asserts the connection has a document in its transaction collection that has the given
+ * sessionId, txnNumber, and lastWriteOptimeTs.
+ */
+ function checkTransactionTable(conn, lsid, txnNumber, ts) {
+ let table = conn.getDB("config").transactions;
+ let res = table.findOne({"_id.id": lsid.id});
+
+ assert.eq(res.txnNum, txnNumber);
+ assert.eq(res.lastWriteOpTime.ts, ts);
+ }
+
+ /**
+ * Asserts the transaction collection document for the given session id is the same on both
+ * connections.
+ */
+ function assertSameRecordOnBothConnections(primary, secondary, lsid) {
+ let primaryRecord = primary.getDB("config").transactions.findOne({"_id.id": lsid.id});
+ let secondaryRecord = secondary.getDB("config").transactions.findOne({"_id.id": lsid.id});
+
+ assert.eq(bsonWoCompare(primaryRecord, secondaryRecord),
+ 0,
+ "expected transaction records: " + tojson(primaryRecord) + " and " +
+ tojson(secondaryRecord) + " to be the same for lsid: " + tojson(lsid));
+ }
+
+ return {
+ isRetryableCode,
+ isRetryableWriteCmdName,
+ storageEngineSupportsRetryableWrites,
+ checkTransactionTable,
+ assertSameRecordOnBothConnections,
+ };
})();
diff --git a/jstests/replsets/transaction_table_oplog_replay.js b/jstests/replsets/transaction_table_oplog_replay.js
index 7ffb1543ce1..b40ab630a49 100644
--- a/jstests/replsets/transaction_table_oplog_replay.js
+++ b/jstests/replsets/transaction_table_oplog_replay.js
@@ -12,32 +12,6 @@
}
/**
- * Asserts the connection has a document in its transaction collection that has the given
- * sessionId, txnNumber, and lastWriteOptimeTs.
- */
- function checkTransactionTable(conn, lsid, txnNumber, ts) {
- let table = conn.getDB("config").transactions;
- let res = table.findOne({"_id.id": lsid.id});
-
- assert.eq(res.txnNum, txnNumber);
- assert.eq(res.lastWriteOpTime.ts, ts);
- }
-
- /**
- * Asserts the transaction collection document for the given session id is the same on both
- * connections.
- */
- function assertSameRecordOnBothConnections(primary, secondary, lsid) {
- let primaryRecord = primary.getDB("config").transactions.findOne({"_id.id": lsid.id});
- let secondaryRecord = secondary.getDB("config").transactions.findOne({"_id.id": lsid.id});
-
- assert.eq(bsonWoCompare(primaryRecord, secondaryRecord),
- 0,
- "expected transaction records: " + tojson(primaryRecord) + " and " +
- tojson(secondaryRecord) + " to be the same for lsid: " + tojson(lsid));
- }
-
- /**
* Runs each command on the primary, awaits replication then asserts the secondary's transaction
* collection has been updated to store the latest txnNumber and lastWriteOpTimeTs for each
* sessionId.
@@ -51,7 +25,7 @@
let res = assert.commandWorked(primary.getDB("test").runCommand(cmd));
let opTime = (res.opTime.ts ? res.opTime.ts : res.opTime);
- checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
+ RetryableWritesUtil.checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
responseTimestamps.push(opTime);
});
@@ -59,12 +33,13 @@
secondary.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"});
replTest.awaitReplication();
cmds.forEach(function(cmd, i) {
- checkTransactionTable(secondary, cmd.lsid, cmd.txnNumber, responseTimestamps[i]);
+ RetryableWritesUtil.checkTransactionTable(
+ secondary, cmd.lsid, cmd.txnNumber, responseTimestamps[i]);
});
// Both nodes should have the same transaction collection record for each sessionId.
cmds.forEach(function(cmd) {
- assertSameRecordOnBothConnections(primary, secondary, cmd.lsid);
+ RetryableWritesUtil.assertSameRecordOnBothConnections(primary, secondary, cmd.lsid);
});
}
@@ -83,7 +58,7 @@
let res = assert.commandWorked(primary.getDB("test").runCommand(cmd));
let opTime = (res.opTime.ts ? res.opTime.ts : res.opTime);
- checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
+ RetryableWritesUtil.checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
latestOpTimeTs = opTime;
highestTxnNumber =
(cmd.txnNumber > highestTxnNumber ? cmd.txnNumber : highestTxnNumber);
@@ -93,10 +68,11 @@
// highest transaction number and the latest write optime.
secondary.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"});
replTest.awaitReplication();
- checkTransactionTable(secondary, cmds[0].lsid, highestTxnNumber, latestOpTimeTs);
+ RetryableWritesUtil.checkTransactionTable(
+ secondary, cmds[0].lsid, highestTxnNumber, latestOpTimeTs);
// Both nodes should have the same transaction collection record for the sessionId.
- assertSameRecordOnBothConnections(primary, secondary, cmds[0].lsid);
+ RetryableWritesUtil.assertSameRecordOnBothConnections(primary, secondary, cmds[0].lsid);
}
const replTest = new ReplSetTest({nodes: 2});