summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2019-05-24 15:28:03 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2019-05-28 16:02:19 -0400
commitef8d28dc326f33c637123f169e1ee3ce3219ee09 (patch)
tree6c6533b1c707429da4f62475db8233b3ec97f043
parent6aab87a22ec4bd89c8ef6495eeaded0829ccff7f (diff)
downloadmongo-ef8d28dc326f33c637123f169e1ee3ce3219ee09.tar.gz
SERVER-41280 JS tests shouldn't assume the prepare oplog entry is the first in transaction
-rw-r--r--jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js24
-rw-r--r--jstests/replsets/inmemory_preserves_active_txns.js7
-rw-r--r--jstests/replsets/rollover_preserves_active_txns.js6
3 files changed, 19 insertions, 18 deletions
diff --git a/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js b/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js
index 35818e94b0d..81ec147934a 100644
--- a/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js
+++ b/jstests/noPassthrough/server_transaction_metrics_for_prepared_transactions.js
@@ -5,6 +5,7 @@
(function() {
"use strict";
load("jstests/core/txns/libs/prepare_helpers.js");
+ load("jstests/replsets/rslib.js");
/**
* Verifies that the serverStatus response has the fields that we expect.
@@ -39,9 +40,9 @@
/**
* Verifies that the timestamp of the oldest active transaction in the transactions table
- * has the value we expect.
+ * is greater than the lower bound and less than or equal to the upper bound.
*/
- function verifyOldestActiveTransactionTimestamp(testDB, expectedTimestamp) {
+ function verifyOldestActiveTransactionTimestamp(testDB, lowerBound, upperBound) {
let res = assert.commandWorked(
testDB.getSiblingDB("config").getCollection("transactions").runCommand("find", {
"filter": {"state": {"$in": ["prepared", "inProgress"]}},
@@ -53,10 +54,13 @@
let entry = res.cursor.firstBatch[0];
assert.neq(undefined, entry);
- assert.eq(entry.startOpTime.ts,
- expectedTimestamp,
- "expected the timestamp of the oldest active transaction to have a value of " +
- expectedTimestamp);
+ assert.lt(lowerBound,
+ entry.startOpTime.ts,
+ "oldest active transaction timestamp should be greater than the lower bound");
+ assert.lte(
+ entry.startOpTime.ts,
+ upperBound,
+ "oldest active transaction timestamp should be less than or equal to the upper bound");
}
// Set up the replica set.
@@ -92,6 +96,7 @@
session.startTransaction();
assert.commandWorked(sessionColl.insert(doc1));
+ const opTimeBeforePrepareForCommit = getLastOpTime(primary);
const prepareTimestampForCommit = PrepareHelpers.prepareTransaction(session);
// Verify the total and current prepared transaction counter is updated and the oldest active
@@ -105,7 +110,8 @@
// Verify that the prepare entry has the oldest timestamp of any active transaction
// in the transactions table.
- verifyOldestActiveTransactionTimestamp(testDB, prepareTimestampForCommit);
+ verifyOldestActiveTransactionTimestamp(
+ testDB, opTimeBeforePrepareForCommit.ts, prepareTimestampForCommit);
// Verify the total prepared and committed transaction counters are updated after a commit
// and that the current prepared counter is decremented.
@@ -132,6 +138,7 @@
session.startTransaction();
assert.commandWorked(sessionColl.insert(doc2));
+ const opTimeBeforePrepareForAbort = getLastOpTime(primary);
const prepareTimestampForAbort = PrepareHelpers.prepareTransaction(session);
// Verify that the total and current prepared counter is updated and the oldest active oplog
@@ -145,7 +152,8 @@
// Verify that the prepare entry has the oldest timestamp of any active transaction
// in the transactions table.
- verifyOldestActiveTransactionTimestamp(testDB, prepareTimestampForAbort);
+ verifyOldestActiveTransactionTimestamp(
+ testDB, opTimeBeforePrepareForAbort.ts, prepareTimestampForAbort);
// Verify the total prepared and aborted transaction counters are updated after an abort and the
// current prepared counter is decremented.
diff --git a/jstests/replsets/inmemory_preserves_active_txns.js b/jstests/replsets/inmemory_preserves_active_txns.js
index 404181e7b4b..c5c6231c43e 100644
--- a/jstests/replsets/inmemory_preserves_active_txns.js
+++ b/jstests/replsets/inmemory_preserves_active_txns.js
@@ -64,11 +64,8 @@
jsTestLog("Get transaction entry from config.transactions");
const txnEntry = primary.getDB("config").transactions.findOne();
- if (TestData.setParameters.useMultipleOplogEntryFormatForTransactions) {
- assert.lt(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
- } else {
- assert.eq(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
- }
+ // The prepare oplog entry may or may not be the first oplog entry depending on packing.
+ assert.lte(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
assert.soonNoExcept(() => {
const secondaryTxnEntry = secondary.getDB("config").transactions.findOne();
diff --git a/jstests/replsets/rollover_preserves_active_txns.js b/jstests/replsets/rollover_preserves_active_txns.js
index 64c58a35cc8..0e3eea0ca19 100644
--- a/jstests/replsets/rollover_preserves_active_txns.js
+++ b/jstests/replsets/rollover_preserves_active_txns.js
@@ -49,11 +49,7 @@
jsTestLog("Get transaction entry from config.transactions");
const txnEntry = primary.getDB("config").transactions.findOne();
- if (TestData.setParameters.useMultipleOplogEntryFormatForTransactions) {
- assert.lte(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
- } else {
- assert.eq(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
- }
+ assert.lte(txnEntry.startOpTime.ts, prepareTimestamp, tojson(txnEntry));
assert.soonNoExcept(() => {
const secondaryTxnEntry = secondary.getDB("config").transactions.findOne();