diff options
author | Benety Goh <benety@mongodb.com> | 2018-04-04 13:47:34 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2018-04-04 13:47:34 -0400 |
commit | c04aa22602fd1640758886b9945a987214f08c88 (patch) | |
tree | 14c3e5f1d8d35266d27b9dd3ff74db15e1b2e160 /jstests/libs/retryable_writes_util.js | |
parent | 4c42865f840749592ce16f4e0858b09522e6a74d (diff) | |
download | mongo-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/libs/retryable_writes_util.js')
-rw-r--r-- | jstests/libs/retryable_writes_util.js | 34 |
1 files changed, 33 insertions, 1 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, + }; })(); |