summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2020-04-08 10:38:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-14 13:17:46 +0000
commit8527f47556d07c22c79f79408238e64f7695decf (patch)
tree9f8b97696c87936323195f4b8571d2131a8aa31e /jstests
parent656ee188b8db0c2ed0e00652ec1c0c47b964a795 (diff)
downloadmongo-8527f47556d07c22c79f79408238e64f7695decf.tar.gz
SERVER-47400 Disallow createCollection/Indexes on system colls in txns
(cherry picked from commit 76d4548a751a56c8faf1887114685b540203a650)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/txns/no_writes_to_system_collections_in_txn.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/jstests/core/txns/no_writes_to_system_collections_in_txn.js b/jstests/core/txns/no_writes_to_system_collections_in_txn.js
index a5956723b1e..ab842be7cc1 100644
--- a/jstests/core/txns/no_writes_to_system_collections_in_txn.js
+++ b/jstests/core/txns/no_writes_to_system_collections_in_txn.js
@@ -3,14 +3,31 @@
(function() {
"use strict";
-const session = db.getMongo().startSession({causalConsistency: false});
+const session = db.getMongo().startSession();
// Use a custom database, to avoid conflict with other tests that use the system.js collection.
const testDB = session.getDatabase("no_writes_system_collections_in_txn");
assert.commandWorked(testDB.dropDatabase());
-const systemColl = testDB.getCollection("system.js");
+const systemCollName = "system.js";
+const systemColl = testDB.getCollection(systemCollName);
const systemDotViews = testDB.getCollection("system.views");
+// createCollection is not presently allowed to run in transactions that have a non-local
+// readConcern.
+// TODO(SERVER-46971) Replace "local" with "snapshot".
+session.startTransaction({readConcern: {level: "local"}});
+assert.commandFailedWithCode(testDB.createCollection(systemCollName),
+ ErrorCodes.OperationNotSupportedInTransaction);
+assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
+
+// createIndexes is not presently allowed to run in transactions that have a non-local
+// readConcern.
+// TODO(SERVER-46971) Replace "local" with "snapshot".
+session.startTransaction({readConcern: {level: "local"}});
+assert.commandFailedWithCode(systemColl.createIndex({name: 1}),
+ ErrorCodes.OperationNotSupportedInTransaction);
+assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
+
// Ensure that a collection exists with at least one document.
assert.commandWorked(systemColl.insert({name: 0}, {writeConcern: {w: "majority"}}));