summaryrefslogtreecommitdiff
path: root/jstests/concurrency
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-02-02 16:07:52 -0500
committerDavid Storch <david.storch@10gen.com>2015-02-03 09:58:13 -0500
commit1e93bc47d0e9e4c75f0d64b507916767bbaee0b9 (patch)
tree4343270e1df89bf26cfdea500fe4c5e3cc62f2c2 /jstests/concurrency
parent37c51fa184f5439bed7a3ce157ea11fad1303177 (diff)
downloadmongo-1e93bc47d0e9e4c75f0d64b507916767bbaee0b9.tar.gz
SERVER-17132 add regression test for duplicate index entries bug
Diffstat (limited to 'jstests/concurrency')
-rw-r--r--jstests/concurrency/fsm_workloads/update_check_index.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/update_check_index.js b/jstests/concurrency/fsm_workloads/update_check_index.js
new file mode 100644
index 00000000000..1f7ba38c1e0
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/update_check_index.js
@@ -0,0 +1,66 @@
+'use strict';
+
+/**
+ * update_check_index.js
+ *
+ * Ensures that concurrent multi updates cannot produce duplicate index entries. Regression test
+ * for SERVER-17132.
+ */
+var $config = (function() {
+
+ var states = (function() {
+ function multiUpdate(db, collName) {
+ // Set 'c' to some random value.
+ var newC = Random.randInt(1000);
+ db[collName].update({a: 1, b: 1}, {$set: {c: newC}}, {multi: true});
+ }
+
+ return {
+ multiUpdate: multiUpdate
+ };
+ })();
+
+ var transitions = {
+ multiUpdate: { multiUpdate: 1.0 }
+ };
+
+ function setup(db, collName) {
+ assertAlways.commandWorked(db[collName].ensureIndex({a: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({b: 1}));
+ assertAlways.commandWorked(db[collName].ensureIndex({c: 1}));
+
+ for (var i = 0; i < 10; i++) {
+ assertAlways.writeOK(db[collName].insert({a: 1, b: 1, c: 1}));
+ }
+ }
+
+ // Asserts that the number of index entries for all three entries matches the number of docs
+ // in the collection. This condition should always be true for non-multikey indices. If it is
+ // not true, then the index has been corrupted.
+ function teardown(db, collName) {
+ assertWhenOwnColl(function() {
+ var numIndexKeys = db[collName].find({}, {_id: 0, a: 1}).hint({a: 1}).itcount();
+ var numDocs = db[collName].find().itcount();
+ assertWhenOwnColl.eq(numIndexKeys, numDocs,
+ 'index {a: 1} has wrong number of index keys');
+
+ numIndexKeys = db[collName].find({}, {_id: 0, b: 1}).hint({b: 1}).itcount();
+ assertWhenOwnColl.eq(numIndexKeys, numDocs,
+ 'index {b: 1} has wrong number of index keys');
+
+ numIndexKeys = db[collName].find({}, {_id: 0, c: 1}).hint({c: 1}).itcount();
+ assertWhenOwnColl.eq(numIndexKeys, numDocs,
+ 'index {c: 1} has wrong number of index keys');
+ });
+ }
+
+ return {
+ threadCount: 10,
+ iterations: 100,
+ states: states,
+ startState: 'multiUpdate',
+ transitions: transitions,
+ setup: setup,
+ teardown: teardown
+ };
+})();