summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-07-28 12:05:03 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-07-28 12:05:03 -0400
commit4154010d81ccbc37e7eeb469887c0a1a75e9538b (patch)
tree1876a858a663d3639563c57ae2944dfefa11229e
parent4ce91b2d6f4c320e73dac117eb6a10058d28fa8c (diff)
downloadmongo-4154010d81ccbc37e7eeb469887c0a1a75e9538b.tar.gz
SERVER-24693 Test that the "group" command yields using explain().
(cherry picked from commit 5042151e09a828880658dd6f3cadee0e0eff2ec1)
-rw-r--r--jstests/core/group7.js47
-rw-r--r--jstests/noPassthrough/yield_group.js32
2 files changed, 32 insertions, 47 deletions
diff --git a/jstests/core/group7.js b/jstests/core/group7.js
deleted file mode 100644
index 6d6ef03e99d..00000000000
--- a/jstests/core/group7.js
+++ /dev/null
@@ -1,47 +0,0 @@
-// Test yielding group command SERVER-1395
-
-t = db.jstests_group7;
-t.drop();
-
-function checkForYield(docs, updates) {
- t.drop();
- a = 0;
- for (var i = 0; i < docs; ++i) {
- t.save({a: a});
- }
-
- // Iteratively update all a values atomically.
- p = startParallelShell(
- 'for( a = 0; a < ' + updates + '; ++a ) {' +
- 'db.jstests_group7.update({ $atomic: true }, { $set: { a: a }}, false, true);' +
- '}');
-
- for (var i = 0; i < updates; ++i) {
- print("running group " + i + " of " + updates);
- ret = t.group({key: {a: 1}, reduce: function() {}, initial: {}});
- // Check if group sees more than one a value, indicating that it yielded.
- if (ret.length > 1) {
- p();
- return true;
- }
- printjson(ret);
- }
-
- p();
- return false;
-}
-
-var yielded = false;
-var docs = 1500;
-var updates = 50;
-for (var j = 1; j <= 6; ++j) {
- print("Iteration " + j + " docs = " + docs + " updates = " + updates);
- if (checkForYield(docs, updates)) {
- yielded = true;
- break;
- }
- // Increase docs and updates to encourage yielding.
- docs *= 2;
- updates *= 2;
-}
-assert(yielded);
diff --git a/jstests/noPassthrough/yield_group.js b/jstests/noPassthrough/yield_group.js
new file mode 100644
index 00000000000..4eb40623e19
--- /dev/null
+++ b/jstests/noPassthrough/yield_group.js
@@ -0,0 +1,32 @@
+/**
+ * Test that the "group" command yields periodically (SERVER-1395).
+ */
+(function() {
+ 'use strict';
+
+ const nDocsToInsert = 300;
+ const worksPerYield = 50;
+
+ // Start a mongod that will yield every 50 work cycles.
+ var conn =
+ MongoRunner.runMongod({setParameter: `internalQueryExecYieldIterations=${worksPerYield}`});
+ assert.neq(null, conn, 'mongod was unable to start up');
+
+ var coll = conn.getDB('test').yield_group;
+
+ var bulk = coll.initializeUnorderedBulkOp();
+ for (var i = 0; i < nDocsToInsert; ++i) {
+ bulk.insert({_id: i});
+ }
+
+ var res = bulk.execute();
+ assert.writeOK(res);
+ assert.eq(nDocsToInsert, res.nInserted, tojson(res));
+
+ // A "group" command performing a collection scan should yield approximately
+ // nDocsToInsert / worksPerYield times.
+ var explain =
+ coll.explain('executionStats').group({key: {_id: 1}, reduce: function() {}, initial: {}});
+ var numYields = explain.executionStats.executionStages.saveState;
+ assert.gt(numYields, (nDocsToInsert / worksPerYield) - 2, tojson(explain));
+})();