diff options
author | Sanika Phanse <sanika.phanse@mongodb.com> | 2022-11-23 01:14:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-23 01:43:39 +0000 |
commit | 2886270e83bf6550e9dabdc4abc88c34873c581d (patch) | |
tree | 61490dbe6a882945b650c1ad9787ab364b95a72d /jstests | |
parent | 48f58b60b414ca216a2ee80361e4bb9d34f556c5 (diff) | |
download | mongo-2886270e83bf6550e9dabdc4abc88c34873c581d.tar.gz |
SERVER-70945 Make findAndModify without a shard key correctly run in a session
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/updateOne_without_shard_key/find_and_modify_without_shard_key.js | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/jstests/sharding/updateOne_without_shard_key/find_and_modify_without_shard_key.js b/jstests/sharding/updateOne_without_shard_key/find_and_modify_without_shard_key.js index 0d8dabe6d66..1ad2b8c243c 100644 --- a/jstests/sharding/updateOne_without_shard_key/find_and_modify_without_shard_key.js +++ b/jstests/sharding/updateOne_without_shard_key/find_and_modify_without_shard_key.js @@ -1,6 +1,6 @@ /** * Test success of findAndModify without shard key command with various query filters, - * run against a sharded cluster, when updateOneWithoutShardKey feature flag is enabled. + * on a sharded collection. * * @tags: [ * requires_sharding, @@ -95,11 +95,21 @@ function verifySingleModification(testCase, res) { }); } -function runCommandAndVerify(testCase) { - jsTest.log(testCase.logMessage + "\n" + tojson(testCase.cmdObj)); +function runCommandAndVerify(testCase, additionalCmdFields = {}) { + const cmdObjWithAdditionalFields = Object.assign({}, testCase.cmdObj, additionalCmdFields); + jsTest.log(tojson(cmdObjWithAdditionalFields)); assert.commandWorked(testColl.insert(testCase.insertDoc)); - const res = st.getDB(dbName).runCommand(testCase.cmdObj); + const res = st.getDB(dbName).runCommand(cmdObjWithAdditionalFields); + + if (cmdObjWithAdditionalFields.hasOwnProperty("autocommit") && !testCase.errorCode) { + assert.commandWorked(st.s.getDB(dbName).adminCommand({ + commitTransaction: 1, + lsid: cmdObjWithAdditionalFields.lsid, + txnNumber: cmdObjWithAdditionalFields.txnNumber, + autocommit: false + })); + } if (testCase.insertDoc.length > 1) { return verifySingleModification(testCase, res); @@ -202,9 +212,20 @@ const testCases = [ }, ]; +jsTest.log("Testing findAndModify without a shard key commands in various configurations."); testCases.forEach(testCase => { - jsTest.log("Testing findAndModify without a shard key commands."); + jsTest.log(testCase.logMessage); runCommandAndVerify(testCase); + + const logicalSessionFields = {lsid: {id: UUID()}}; + runCommandAndVerify(testCase, logicalSessionFields); + + const retryableWriteFields = {lsid: {id: UUID()}, txnNumber: NumberLong(0)}; + runCommandAndVerify(testCase, retryableWriteFields); + + const transactionFields = + {lsid: {id: UUID()}, txnNumber: NumberLong(0), startTransaction: true, autocommit: false}; + runCommandAndVerify(testCase, transactionFields); }); st.stop(); |