summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-11-16 19:18:12 -0500
committerMathias Stearn <mathias@10gen.com>2015-11-17 17:35:54 -0500
commitc7206ba504c5c6901cae130c75f8a045393e568e (patch)
tree6997750949dc522a45bd9662f8fc6379b7439bf9 /jstests
parenta7a896f961f49c7839b96e15e6e3b27c66c2611e (diff)
downloadmongo-c7206ba504c5c6901cae130c75f8a045393e568e.tar.gz
SERVER-21488 insert into indexed capped collections one-at-a-time
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/bulk_insert_capped.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/jstests/core/bulk_insert_capped.js b/jstests/core/bulk_insert_capped.js
new file mode 100644
index 00000000000..70edf98ca4e
--- /dev/null
+++ b/jstests/core/bulk_insert_capped.js
@@ -0,0 +1,24 @@
+// SERVER-21488 Test that multi inserts into capped collections don't cause corruption.
+// Note: this file must have a name that starts with "bulk" so it gets run by bulk_gle_passthrough.
+(function() {
+ "use strict";
+ var t = db.capped_multi_insert;
+ t.drop();
+
+ db.createCollection(t.getName(), {capped: true, size: 16*1024, max: 1});
+
+ t.insert([{_id:1}, {_id:2}]);
+ assert.gleSuccess(db);
+
+ // Ensure the collection is valid.
+ var res = t.validate(true);
+ assert(res.valid, tojson(res));
+
+ // Ensure that various ways of iterating the collection only return one document.
+ assert.eq(t.find().itcount(), 1); // Table scan.
+ assert.eq(t.find({}, {_id: 1}).hint({_id: 1}).itcount(), 1); // Index only (covered).
+ assert.eq(t.find().hint({_id: 1}).itcount(), 1); // Index scan with fetch.
+
+ // Ensure that the second document is the one that is kept.
+ assert.eq(t.findOne(), {_id: 2});
+}());