summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js')
-rw-r--r--jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js88
1 files changed, 44 insertions, 44 deletions
diff --git a/jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js b/jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js
index 9dee2103f94..48de0c880c8 100644
--- a/jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js
+++ b/jstests/noPassthrough/transaction_write_with_snapshot_unavailable.js
@@ -9,59 +9,59 @@
* @tags: [uses_transactions]
*/
(function() {
- "use strict";
- load("jstests/libs/check_log.js");
+"use strict";
+load("jstests/libs/check_log.js");
- const name = "transaction_write_with_snapshot_unavailable";
- const replTest = new ReplSetTest({name: name, nodes: 1});
- replTest.startSet();
- replTest.initiate();
+const name = "transaction_write_with_snapshot_unavailable";
+const replTest = new ReplSetTest({name: name, nodes: 1});
+replTest.startSet();
+replTest.initiate();
- const dbName = name;
- const dbNameB = dbName + "B";
- const collName = "collection";
- const collNameB = collName + "B";
+const dbName = name;
+const dbNameB = dbName + "B";
+const collName = "collection";
+const collNameB = collName + "B";
- const primary = replTest.getPrimary();
- const primaryDB = primary.getDB(dbName);
+const primary = replTest.getPrimary();
+const primaryDB = primary.getDB(dbName);
- assert.commandWorked(primaryDB[collName].insertOne({}, {writeConcern: {w: "majority"}}));
+assert.commandWorked(primaryDB[collName].insertOne({}, {writeConcern: {w: "majority"}}));
- function testOp(cmd) {
- let op = Object.getOwnPropertyNames(cmd)[0];
- let session = primary.startSession();
- let sessionDB = session.getDatabase(name);
+function testOp(cmd) {
+ let op = Object.getOwnPropertyNames(cmd)[0];
+ let session = primary.startSession();
+ let sessionDB = session.getDatabase(name);
- jsTestLog(
- `Testing that SnapshotUnavailable during ${op} is labelled TransientTransactionError`);
+ jsTestLog(
+ `Testing that SnapshotUnavailable during ${op} is labelled TransientTransactionError`);
- session.startTransaction({readConcern: {level: "snapshot"}});
- assert.commandWorked(sessionDB.runCommand({insert: collName, documents: [{}]}));
- // Create collection outside transaction, cannot write to it in the transaction
- assert.commandWorked(primaryDB.getSiblingDB(dbNameB).runCommand({create: collNameB}));
+ session.startTransaction({readConcern: {level: "snapshot"}});
+ assert.commandWorked(sessionDB.runCommand({insert: collName, documents: [{}]}));
+ // Create collection outside transaction, cannot write to it in the transaction
+ assert.commandWorked(primaryDB.getSiblingDB(dbNameB).runCommand({create: collNameB}));
- let res;
- try {
- res = sessionDB.getSiblingDB(dbNameB).runCommand(cmd);
- assert.commandFailedWithCode(res, ErrorCodes.SnapshotUnavailable);
- assert.eq(res.ok, 0);
- assert(!res.hasOwnProperty("writeErrors"));
- assert.eq(res.errorLabels, ["TransientTransactionError"]);
- } catch (ex) {
- printjson(cmd);
- printjson(res);
- throw ex;
- }
-
- assert.commandFailedWithCode(session.abortTransaction_forTesting(),
- ErrorCodes.NoSuchTransaction);
- assert.commandWorked(primaryDB.getSiblingDB(dbNameB).runCommand(
- {dropDatabase: 1, writeConcern: {w: "majority"}}));
+ let res;
+ try {
+ res = sessionDB.getSiblingDB(dbNameB).runCommand(cmd);
+ assert.commandFailedWithCode(res, ErrorCodes.SnapshotUnavailable);
+ assert.eq(res.ok, 0);
+ assert(!res.hasOwnProperty("writeErrors"));
+ assert.eq(res.errorLabels, ["TransientTransactionError"]);
+ } catch (ex) {
+ printjson(cmd);
+ printjson(res);
+ throw ex;
}
- testOp({insert: collNameB, documents: [{_id: 0}]});
- testOp({update: collNameB, updates: [{q: {}, u: {$set: {x: 1}}}]});
- testOp({delete: collNameB, deletes: [{q: {_id: 0}, limit: 1}]});
+ assert.commandFailedWithCode(session.abortTransaction_forTesting(),
+ ErrorCodes.NoSuchTransaction);
+ assert.commandWorked(primaryDB.getSiblingDB(dbNameB).runCommand(
+ {dropDatabase: 1, writeConcern: {w: "majority"}}));
+}
+
+testOp({insert: collNameB, documents: [{_id: 0}]});
+testOp({update: collNameB, updates: [{q: {}, u: {$set: {x: 1}}}]});
+testOp({delete: collNameB, deletes: [{q: {_id: 0}, limit: 1}]});
- replTest.stopSet();
+replTest.stopSet();
})();