summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/pipeline_optimization_failpoint.js
diff options
context:
space:
mode:
authorDavid Bradford <david.bradford@mongodb.com>2018-07-30 15:08:06 -0400
committerDavid Bradford <david.bradford@mongodb.com>2018-07-30 15:08:12 -0400
commit7439edb75ee2c02c210dd0c9290193c9264236ac (patch)
tree13a0160ad1998b575daf3c9d5f56efb268e7cda9 /jstests/noPassthrough/pipeline_optimization_failpoint.js
parentb0bb4da6f7f04ab7ec407f7bdbc571e5e6ec3185 (diff)
downloadmongo-7439edb75ee2c02c210dd0c9290193c9264236ac.tar.gz
SERVER-36308: Ensure pipeline optimization failpoint tests are deterministic
Diffstat (limited to 'jstests/noPassthrough/pipeline_optimization_failpoint.js')
-rw-r--r--jstests/noPassthrough/pipeline_optimization_failpoint.js27
1 files changed, 14 insertions, 13 deletions
diff --git a/jstests/noPassthrough/pipeline_optimization_failpoint.js b/jstests/noPassthrough/pipeline_optimization_failpoint.js
index 1cf443714a9..46ac0d162bc 100644
--- a/jstests/noPassthrough/pipeline_optimization_failpoint.js
+++ b/jstests/noPassthrough/pipeline_optimization_failpoint.js
@@ -4,33 +4,34 @@
"use strict";
load("jstests/libs/analyze_plan.js"); // For aggPlan functions.
-
- const pipeline = [{$match: {state: "OH"}}, {$sort: {pop: -1}}, {$limit: 10}];
+ Random.setRandomSeed();
const conn = MongoRunner.runMongod({});
- assert.neq(conn, null, `Mongod failed to start up.`);
+ assert.neq(conn, null, "Mongod failed to start up.");
const testDb = conn.getDB("test");
const coll = testDb.agg_opt;
+ const pops = new Set();
for (let i = 0; i < 25; ++i) {
- assert.commandWorked(coll.insert({
- _id: i,
- city: "Cleveland",
- pop: Math.floor(Math.random() * 100000) + 100,
- state: "OH"
- }));
+ let pop;
+ do {
+ pop = Random.randInt(100000);
+ } while (pops.has(pop));
+
+ assert.commandWorked(coll.insert({_id: i, city: "Cleveland", pop: pop, state: "OH"}));
}
+ const pipeline = [{$match: {state: "OH"}}, {$sort: {pop: -1}}, {$limit: 10}];
+
const enabledPlan = coll.explain().aggregate(pipeline);
// Test that sort and the limit were combined.
assert.eq(aggPlanHasStage(enabledPlan, "$limit"), false);
assert.eq(aggPlanHasStage(enabledPlan, "$sort"), true);
assert.eq(enabledPlan.stages.length, 2);
- const enabledResult = coll.aggregate(pipeline);
+ const enabledResult = coll.aggregate(pipeline).toArray();
- // Enable a failpoint that will cause pipeline optimizations to be skipped. Test that the
- // pipeline isn't modified after it's specified.
+ // Enable a failpoint that will cause pipeline optimizations to be skipped.
assert.commandWorked(
testDb.adminCommand({configureFailPoint: "disablePipelineOptimization", mode: "alwaysOn"}));
@@ -40,7 +41,7 @@
assert.eq(aggPlanHasStage(disabledPlan, "$sort"), true);
assert.eq(disabledPlan.stages.length, 3);
- const disabledResult = coll.aggregate(pipeline);
+ const disabledResult = coll.aggregate(pipeline).toArray();
// Test that the result is the same with and without optimizations enabled.
assert.eq(enabledResult, disabledResult);