summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2019-04-25 16:56:58 -0400
committerLingzhi Deng <lingzhi.deng@mongodb.com>2019-04-29 16:33:55 -0400
commita7b6ea4c7c51069eb85b789d078210ec2852e5e0 (patch)
tree11eb2226872ed441f7789f54364e18ab17917b7f
parente3796fef68ec17ef475e669cd04193aac506bf58 (diff)
downloadmongo-a7b6ea4c7c51069eb85b789d078210ec2852e5e0.tar.gz
SERVER-40839: Add tests for empty unprepared transactions
-rw-r--r--buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml4
-rw-r--r--buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml4
-rw-r--r--buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml4
-rw-r--r--buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml4
-rw-r--r--jstests/core/txns/empty_commit_abort.js64
5 files changed, 80 insertions, 0 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml
index 64c70dcae67..6d3d50de224 100644
--- a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml
@@ -41,6 +41,10 @@ selector:
# attached to statements in a transaction beyond the first one.
- jstests/core/txns/non_transactional_operations_on_session_with_transaction.js
+ # Empty commit/abort is currently allowed in mongos.
+ # TODO: SERVER-40885: unblacklist this.
+ - jstests/core/txns/empty_commit_abort.js
+
exclude_with_any_tags:
# Transactions are not allowed to operate on capped collections on shard servers.
- requires_capped
diff --git a/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml
index 58a186ac39f..72b079cc5c9 100644
--- a/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml
@@ -40,6 +40,10 @@ selector:
# attached to statements in a transaction beyond the first one.
- jstests/core/txns/non_transactional_operations_on_session_with_transaction.js
+ # Empty commit/abort is currently allowed in mongos.
+ # TODO: SERVER-40885: unblacklist this.
+ - jstests/core/txns/empty_commit_abort.js
+
exclude_with_any_tags:
- assumes_against_mongod_not_mongos
# Tests tagged with the following will fail because they assume collections are not sharded.
diff --git a/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml b/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml
index 44fd20dd3d0..e7af387796c 100644
--- a/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml
+++ b/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml
@@ -37,6 +37,10 @@ selector:
# Uses hangAfterCollectionInserts failpoint not available on mongos.
- jstests/core/txns/speculative_snapshot_includes_all_writes.js
+ # Empty commit/abort is currently allowed in mongos.
+ # TODO: SERVER-40885: unblacklist this.
+ - jstests/core/txns/empty_commit_abort.js
+
exclude_with_any_tags:
# Transactions are not allowed to operate on capped collections on shard servers.
- requires_capped
diff --git a/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml b/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml
index 9f7b44b40c5..7e9914e833a 100644
--- a/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml
+++ b/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml
@@ -36,6 +36,10 @@ selector:
# View tests aren't expected to work when collections are implicitly sharded.
- jstests/core/txns/view_reads_in_transaction.js
+ # Empty commit/abort is currently allowed in mongos.
+ # TODO: SERVER-40885: unblacklist this.
+ - jstests/core/txns/empty_commit_abort.js
+
exclude_with_any_tags:
- assumes_against_mongod_not_mongos
# Tests tagged with the following will fail because they assume collections are not sharded.
diff --git a/jstests/core/txns/empty_commit_abort.js b/jstests/core/txns/empty_commit_abort.js
new file mode 100644
index 00000000000..0b65ffab94f
--- /dev/null
+++ b/jstests/core/txns/empty_commit_abort.js
@@ -0,0 +1,64 @@
+/**
+ * Tests transactions that commit/abort after no writes.
+ *
+ * @tags: [uses_transactions]
+ */
+(function() {
+ "use strict";
+
+ const dbName = "test";
+ const collName = "empty_commit_abort";
+ const testDB = db.getSiblingDB(dbName);
+ const testColl = testDB.getCollection(collName);
+
+ testColl.drop({writeConcern: {w: "majority"}});
+ assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}}));
+
+ const doc = {_id: 1, a: 1, b: 1};
+ assert.commandWorked(testColl.insert(doc));
+
+ const session = db.getMongo().startSession();
+ const sessionDB = session.getDatabase(dbName);
+ const sessionColl = sessionDB.getCollection(collName);
+
+ // ---- Test 1. No operations before commit ----
+ session.startTransaction();
+ assert.commandFailedWithCode(sessionDB.adminCommand({commitTransaction: 1}),
+ ErrorCodes.OperationNotSupportedInTransaction);
+ assert.commandFailedWithCode(session.abortTransaction_forTesting(),
+ ErrorCodes.NoSuchTransaction);
+
+ // ---- Test 2. No operations before abort ----
+ session.startTransaction();
+ assert.commandFailedWithCode(sessionDB.adminCommand({abortTransaction: 1}),
+ ErrorCodes.OperationNotSupportedInTransaction);
+ assert.commandFailedWithCode(session.abortTransaction_forTesting(),
+ ErrorCodes.NoSuchTransaction);
+
+ // ---- Test 3. Only reads before commit ----
+ session.startTransaction();
+ assert.eq(doc, sessionColl.findOne({a: 1}));
+ assert.commandWorked(session.commitTransaction_forTesting());
+
+ // ---- Test 4. Only reads before abort ----
+ session.startTransaction();
+ assert.eq(doc, sessionColl.findOne({a: 1}));
+ assert.commandWorked(session.abortTransaction_forTesting());
+
+ // ---- Test 5. Noop writes before commit ----
+ session.startTransaction();
+ let res = assert.commandWorked(sessionColl.update({a: 1}, {$set: {b: 1}}));
+ assert.eq(res.nMatched, 1, tojson(res));
+ assert.eq(res.nModified, 0, tojson(res));
+ assert.eq(res.nUpserted, 0, tojson(res));
+ assert.commandWorked(session.commitTransaction_forTesting());
+
+ // ---- Test 6. Noop writes before abort ----
+ session.startTransaction();
+ res = assert.commandWorked(sessionColl.update({a: 1}, {$set: {b: 1}}));
+ assert.eq(res.nMatched, 1, tojson(res));
+ assert.eq(res.nModified, 0, tojson(res));
+ assert.eq(res.nUpserted, 0, tojson(res));
+ assert.commandWorked(session.abortTransaction_forTesting());
+
+}());