diff options
author | Maria van Keulen <maria@mongodb.com> | 2020-03-09 11:31:34 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-12 16:12:40 +0000 |
commit | 90c3f10389519068eb685db72b7ff13f93c71dc6 (patch) | |
tree | c99bc77ca9b713b73270deeabd4c0c47dfac3d84 /jstests/libs/create_collection_txn_helpers.js | |
parent | db3a17bbfe2e265722ed88df961e79f3e1a68067 (diff) | |
download | mongo-90c3f10389519068eb685db72b7ff13f93c71dc6.tar.gz |
SERVER-44409 Add FSM and nice-to-have collection and index test cases
Diffstat (limited to 'jstests/libs/create_collection_txn_helpers.js')
-rw-r--r-- | jstests/libs/create_collection_txn_helpers.js | 19 |
1 files changed, 17 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); }; |