summaryrefslogtreecommitdiff
path: root/jstests/libs
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2020-03-09 11:31:34 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-12 20:14:39 +0000
commit11fad729f6ad3d1b546d687bf4541f428de0d0bc (patch)
treeb0af2ae40278973e53a2f4cf1efdb836ef668e98 /jstests/libs
parent08f65f240195e818d8ec8f03c203a9a8c7ed0680 (diff)
downloadmongo-11fad729f6ad3d1b546d687bf4541f428de0d0bc.tar.gz
SERVER-44409 Add FSM and nice-to-have collection and index test cases
(cherry picked from commit 90c3f10389519068eb685db72b7ff13f93c71dc6)
Diffstat (limited to 'jstests/libs')
-rw-r--r--jstests/libs/create_collection_txn_helpers.js19
-rw-r--r--jstests/libs/create_index_txn_helpers.js3
2 files changed, 20 insertions, 2 deletions
diff --git a/jstests/libs/create_collection_txn_helpers.js b/jstests/libs/create_collection_txn_helpers.js
index 9b6ba15eac8..08d7093a5c7 100644
--- a/jstests/libs/create_collection_txn_helpers.js
+++ b/jstests/libs/create_collection_txn_helpers.js
@@ -1,12 +1,27 @@
/**
* Helper function shared by createCollection inside txns tests.
*/
-const createCollAndCRUDInTxn = function(sessionDB, collName, explicitCreate) {
+const createCollAndCRUDInTxn = function(sessionDB, collName, explicitCreate, upsert) {
+ if (undefined === explicitCreate) {
+ doassert('createCollAndCRUDInTxn called with undefined explicitCreate');
+ }
+ if (undefined === upsert) {
+ doassert('createCollAndCRUDInTxn called with undefined upsert');
+ }
if (explicitCreate) {
assert.commandWorked(sessionDB.runCommand({create: collName}));
}
let sessionColl = sessionDB[collName];
- assert.commandWorked(sessionColl.insert({a: 1}));
+ if (upsert) {
+ assert.commandWorked(sessionColl.update({_id: 1}, {$inc: {a: 1}}, {upsert: true}));
+ } else {
+ assert.commandWorked(sessionColl.insert({a: 1}));
+ }
assert.eq(sessionColl.find({a: 1}).itcount(), 1);
+ assert.commandWorked(sessionColl.insert({_id: 2}));
+ let resDoc = sessionColl.findAndModify({query: {_id: 2}, update: {$inc: {a: 1}}});
+ assert.eq(resDoc._id, 2);
+ assert.commandWorked(sessionColl.update({_id: 2}, {$inc: {a: 1}}));
+ assert.commandWorked(sessionColl.deleteOne({_id: 2}));
assert.eq(sessionColl.find({}).itcount(), 1);
};
diff --git a/jstests/libs/create_index_txn_helpers.js b/jstests/libs/create_index_txn_helpers.js
index fdc2863a675..73e1ee94fe2 100644
--- a/jstests/libs/create_index_txn_helpers.js
+++ b/jstests/libs/create_index_txn_helpers.js
@@ -23,11 +23,14 @@ const createIndexAndCRUDInTxn = function(sessionDB, collName, explicitCollCreate
}
let sessionColl = sessionDB[collName];
assert.commandWorked(sessionColl.runCommand({createIndexes: collName, indexes: [indexSpecs]}));
+ assert.commandWorked(sessionColl.createIndex({_id: 1}));
if (multikeyIndex) {
assert.commandWorked(sessionColl.insert({a: [1, 2, 3]}));
} else {
assert.commandWorked(sessionColl.insert({a: 1}));
}
assert.eq(sessionColl.find({a: 1}).itcount(), 1);
+ assert.commandWorked(sessionColl.insert({_id: 1}));
+ assert.commandWorked(sessionColl.deleteOne({_id: 1}));
assert.eq(sessionColl.find({}).itcount(), 1);
};