summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2020-05-06 13:12:04 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-13 18:03:25 +0000
commit72432502fba43c6e10e54e94a0d69c751b21ddb7 (patch)
tree0722bed414391b8cd10cc9eaa4bb780d3103cde1
parentf61bcc1b3f7f43b9ea02316f51442a5122eeef5a (diff)
downloadmongo-72432502fba43c6e10e54e94a0d69c751b21ddb7.tar.gz
SERVER-47877 Replace uses of arrayEq without assert with assert.sameMembers in replsets tests
(cherry picked from commit ca9bd540c161f33fcfa271449b89afb80917f382)
-rw-r--r--jstests/aggregation/extras/utils.js7
-rw-r--r--jstests/replsets/apply_ops_inner_ts_field.js7
-rw-r--r--jstests/replsets/commit_prepared_transaction_before_stable_timestamp.js4
-rw-r--r--jstests/replsets/recover_committed_aborted_prepared_transactions.js15
-rw-r--r--jstests/replsets/recover_prepared_transaction_state.js7
-rw-r--r--jstests/replsets/rollback_prepare_transaction.js4
-rw-r--r--jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js5
-rw-r--r--jstests/replsets/startup_recovery_reconstructs_txn_prepared_before_stable_ts.js5
8 files changed, 28 insertions, 26 deletions
diff --git a/jstests/aggregation/extras/utils.js b/jstests/aggregation/extras/utils.js
index 7afef1ec657..2dd25601f60 100644
--- a/jstests/aggregation/extras/utils.js
+++ b/jstests/aggregation/extras/utils.js
@@ -127,6 +127,13 @@ function documentEq(dl, dr, verbose = false, valueComparator) {
return true;
}
+/**
+ * Returns true if both 'al' and 'ar' are arrays of the same length with the same elements according
+ * to valueComparator. Order of the elements within the arrays is not significant.
+ *
+ * This is a predicate, not an assertion; use assert.sameMembers() in assert.js for the
+ * equivalent assertion.
+ */
function arrayEq(al, ar, verbose = false, valueComparator) {
const debug = msg => verbose ? print(msg) : null; // Helper to log 'msg' iff 'verbose' is true.
diff --git a/jstests/replsets/apply_ops_inner_ts_field.js b/jstests/replsets/apply_ops_inner_ts_field.js
index 73ae8f1347e..29e713bd649 100644
--- a/jstests/replsets/apply_ops_inner_ts_field.js
+++ b/jstests/replsets/apply_ops_inner_ts_field.js
@@ -8,7 +8,6 @@
(function() {
"use strict";
-load("jstests/aggregation/extras/utils.js");
const dbName = "test";
const collName = "coll";
@@ -52,8 +51,8 @@ rst.awaitReplication();
// Make sure that the secondary succesfully applies the applyOps oplog entry despite the command
// specifying an invalid inner "ts" field.
-arrayEq(primaryColl.find({_id: 3}).toArray(), [{_id: 3}]);
-arrayEq(secondary.getDB(dbName)[collName].find({_id: 3}).toArray(), [{_id: 3}]);
+assert.sameMembers(primaryColl.find({_id: 3}).toArray(), [{_id: 3}]);
+assert.sameMembers(secondary.getDB(dbName)[collName].find({_id: 3}).toArray(), [{_id: 3}]);
rst.stopSet();
-})(); \ No newline at end of file
+})();
diff --git a/jstests/replsets/commit_prepared_transaction_before_stable_timestamp.js b/jstests/replsets/commit_prepared_transaction_before_stable_timestamp.js
index 56b156d8289..9490544b7ef 100644
--- a/jstests/replsets/commit_prepared_transaction_before_stable_timestamp.js
+++ b/jstests/replsets/commit_prepared_transaction_before_stable_timestamp.js
@@ -50,10 +50,10 @@ jsTestLog("Committing the transaction before the stable timestamp");
assert.commandWorked(PrepareHelpers.commitTransaction(session, prepareTimestamp));
// Make sure we can see the insert from the prepared transaction.
-arrayEq(sessionColl.find().toArray(), [{_id: 1}, {_id: 2}]);
+assert.sameMembers(sessionColl.find().toArray(), [{_id: 1}, {_id: 2}]);
assert.commandWorked(
primary.adminCommand({configureFailPoint: 'WTSetOldestTSToStableTS', mode: 'off'}));
replTest.stopSet();
-}()); \ No newline at end of file
+}());
diff --git a/jstests/replsets/recover_committed_aborted_prepared_transactions.js b/jstests/replsets/recover_committed_aborted_prepared_transactions.js
index b5b88d6c549..5e834fb0395 100644
--- a/jstests/replsets/recover_committed_aborted_prepared_transactions.js
+++ b/jstests/replsets/recover_committed_aborted_prepared_transactions.js
@@ -9,7 +9,6 @@
(function() {
"use strict";
-load("jstests/aggregation/extras/utils.js");
load("jstests/core/txns/libs/prepare_helpers.js");
load("jstests/replsets/libs/rollback_test.js");
@@ -36,13 +35,13 @@ let sessionColl1 = sessionDB1.getCollection(collName);
const sessionDB2 = session2.getDatabase(dbName);
const sessionColl2 = sessionDB2.getCollection(collName);
-assert.commandWorked(sessionColl1.insert({id: 1}));
+assert.commandWorked(sessionColl1.insert({_id: 1}));
rollbackTest.awaitLastOpCommitted();
// Prepare a transaction on the first session which will be committed eventually.
session1.startTransaction();
-assert.commandWorked(sessionColl1.insert({id: 2}));
+assert.commandWorked(sessionColl1.insert({_id: 2}));
const prepareTimestamp = PrepareHelpers.prepareTransaction(session1);
// Prevent the stable timestamp from moving beyond the following prepared transactions so
@@ -55,7 +54,7 @@ assert.commandWorked(
// Prepare another transaction on the second session which will be aborted.
session2.startTransaction();
-assert.commandWorked(sessionColl2.insert({id: 3}));
+assert.commandWorked(sessionColl2.insert({_id: 3}));
const prepareTimestamp2 = PrepareHelpers.prepareTransaction(session2, {w: 1});
// Commit the first transaction.
@@ -69,7 +68,7 @@ assert.eq(primary.getDB('config')['transactions'].find().itcount(), 2);
// The following write will be rolled back.
rollbackTest.transitionToRollbackOperations();
-assert.commandWorked(testColl.insert({id: 4}));
+assert.commandWorked(testColl.insert({_id: 4}));
rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
@@ -87,8 +86,8 @@ assert.eq(primary.getDB('config')['transactions'].find().itcount(), 2);
// Make sure we can see the first two writes and the insert from the first prepared transaction.
// Make sure we cannot see the insert from the second prepared transaction or the writes after
// transitionToRollbackOperations.
-arrayEq(testColl.find().toArray(), [{_id: 1}, {_id: 2}]);
-arrayEq(sessionColl1.find().toArray(), [{_id: 1}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 1}, {_id: 2}]);
+assert.sameMembers(sessionColl1.find().toArray(), [{_id: 1}, {_id: 2}]);
assert.eq(testColl.count(), 2);
assert.eq(sessionColl1.count(), 2);
@@ -128,7 +127,7 @@ assert.commandFailedWithCode(sessionDB1.adminCommand({
ErrorCodes.NoSuchTransaction);
// Make sure we can see the insert after committing the prepared transaction.
-arrayEq(testColl.find().toArray(), [{_id: 1}, {_id: 2}, {_id: 5}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 1}, {_id: 2}, {_id: 5}]);
assert.eq(testColl.count(), 3);
rollbackTest.stop();
diff --git a/jstests/replsets/recover_prepared_transaction_state.js b/jstests/replsets/recover_prepared_transaction_state.js
index 1b054718778..96fe99e3c6b 100644
--- a/jstests/replsets/recover_prepared_transaction_state.js
+++ b/jstests/replsets/recover_prepared_transaction_state.js
@@ -17,7 +17,6 @@
(function() {
"use strict";
-load("jstests/aggregation/extras/utils.js");
load("jstests/core/txns/libs/prepare_helpers.js");
load("jstests/replsets/libs/rollback_test.js");
@@ -102,8 +101,8 @@ assert.eq(primary.getDB('config')['transactions'].find().itcount(), 2);
// Make sure we can only see the first write and cannot see the writes from the prepared
// transactions or the write that was rolled back.
-arrayEq(sessionColl1.find().toArray(), [{_id: 1}, {_id: 2}]);
-arrayEq(testColl.find().toArray(), [{_id: 1}, {_id: 2}]);
+assert.sameMembers(sessionColl1.find().toArray(), [{_id: 1}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 1}, {_id: 2}]);
// This check characterizes the current behavior of fastcount after rollback. It will not be
// correct, but reflects the count at the point where both transactions are not yet committed or
@@ -189,7 +188,7 @@ rollbackTest.awaitReplication();
// Make sure we can see the result of the committed prepared transaction and cannot see the
// write from the aborted transaction.
-arrayEq(testColl.find().toArray(), [{_id: 1, a: 1}, {_id: 2}, {_id: 3}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 1, a: 1}, {_id: 2}, {_id: 3}]);
assert.eq(testColl.count(), 3);
rollbackTest.stop();
diff --git a/jstests/replsets/rollback_prepare_transaction.js b/jstests/replsets/rollback_prepare_transaction.js
index c6f329dd647..4b6ca136896 100644
--- a/jstests/replsets/rollback_prepare_transaction.js
+++ b/jstests/replsets/rollback_prepare_transaction.js
@@ -59,8 +59,8 @@ PrepareHelpers.commitTransaction(session1, prepareTs);
assert.eq(6, testColl.count());
// Check the visible documents.
-arrayEq([{_id: "a"}, {_id: "b"}, {_id: "t2_a"}, {_id: "t2_b"}, {_id: "t2_c"}],
- testColl.find().toArray());
+assert.sameMembers([{_id: "a"}, {_id: "b"}, {_id: "t2_a"}, {_id: "t2_b"}, {_id: "t2_c"}],
+ testColl.find().toArray());
rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
diff --git a/jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js b/jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js
index c468cde2437..94bfb9609b4 100644
--- a/jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js
+++ b/jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js
@@ -7,7 +7,6 @@
(function() {
"use strict";
-load("jstests/aggregation/extras/utils.js");
load("jstests/core/txns/libs/prepare_helpers.js");
load("jstests/replsets/libs/rollback_test.js");
@@ -78,7 +77,7 @@ assert.eq(1, metrics.transactions.currentInactive);
assert.eq(1, metrics.transactions.currentOpen);
// Make sure we cannot see the writes from the prepared transaction yet.
-arrayEq(testColl.find().toArray(), [{_id: 0}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 0}, {_id: 2}]);
// Get the correct primary after the topology changes.
primary = rollbackTest.getPrimary();
@@ -119,7 +118,7 @@ assert.commandWorked(sessionDB.adminCommand({
}));
// Make sure we can see the effects of the prepared transaction.
-arrayEq(testColl.find().toArray(), [{_id: 0, a: 1}, {_id: 1}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 0, a: 1}, {_id: 1}, {_id: 2}]);
assert.eq(testColl.count(), 3);
rollbackTest.stop();
diff --git a/jstests/replsets/startup_recovery_reconstructs_txn_prepared_before_stable_ts.js b/jstests/replsets/startup_recovery_reconstructs_txn_prepared_before_stable_ts.js
index 27237cbe18f..79b7f930255 100644
--- a/jstests/replsets/startup_recovery_reconstructs_txn_prepared_before_stable_ts.js
+++ b/jstests/replsets/startup_recovery_reconstructs_txn_prepared_before_stable_ts.js
@@ -8,7 +8,6 @@
(function() {
"use strict";
load("jstests/core/txns/libs/prepare_helpers.js");
-load("jstests/aggregation/extras/utils.js");
const replTest = new ReplSetTest({nodes: 1});
replTest.startSet();
@@ -68,7 +67,7 @@ primary = replTest.getPrimary();
testColl = primary.getDB(dbName)[collName];
// Make sure we cannot see the writes from the prepared transaction yet.
-arrayEq(testColl.find().toArray(), [{_id: 0}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 0}, {_id: 2}]);
assert.eq(testColl.count(), 3);
// Make sure there is still one transaction in the transactions table. This is because the
@@ -108,7 +107,7 @@ assert.commandWorked(sessionDB.adminCommand({
}));
// Make sure we can see the effects of the prepared transaction.
-arrayEq(testColl.find().toArray(), [{_id: 0, a: largeArray}, {_id: 1}, {_id: 2}]);
+assert.sameMembers(testColl.find().toArray(), [{_id: 0, a: largeArray}, {_id: 1}, {_id: 2}]);
assert.eq(testColl.count(), 3);
replTest.stopSet();