summaryrefslogtreecommitdiff
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
parentb0bb4da6f7f04ab7ec407f7bdbc571e5e6ec3185 (diff)
downloadmongo-7439edb75ee2c02c210dd0c9290193c9264236ac.tar.gz
SERVER-36308: Ensure pipeline optimization failpoint tests are deterministic
-rw-r--r--jstests/noPassthrough/match_expression_optimization_failpoint.js24
-rw-r--r--jstests/noPassthrough/pipeline_optimization_failpoint.js27
2 files changed, 24 insertions, 27 deletions
diff --git a/jstests/noPassthrough/match_expression_optimization_failpoint.js b/jstests/noPassthrough/match_expression_optimization_failpoint.js
index 75c8c6f3e0c..8cfdf1d51b4 100644
--- a/jstests/noPassthrough/match_expression_optimization_failpoint.js
+++ b/jstests/noPassthrough/match_expression_optimization_failpoint.js
@@ -4,33 +4,29 @@
"use strict";
load("jstests/libs/analyze_plan.js"); // For aggPlan functions.
-
- const kTestZip = 44100;
- const pipeline = [{$match: {_id: {$in: [kTestZip]}}}, {$sort: {_id: 1}}];
+ 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 kTestZip = 44100;
for (let i = 0; i < 25; ++i) {
- assert.commandWorked(coll.insert({
- _id: kTestZip + i,
- city: "Cleveland",
- pop: Math.floor(Math.random() * 100000) + 100,
- state: "OH"
- }));
+ assert.commandWorked(coll.insert(
+ {_id: kTestZip + i, city: "Cleveland", pop: Random.randInt(100000), state: "OH"}));
}
+ const pipeline = [{$match: {_id: {$in: [kTestZip]}}}, {$sort: {_id: 1}}];
+
const enabledPlan = coll.explain().aggregate(pipeline);
// Test that a single equality condition $in was optimized to an $eq.
assert.eq(getAggPlanStage(enabledPlan, "$cursor").$cursor.queryPlanner.parsedQuery._id.$eq,
kTestZip);
- const enabledResult = coll.aggregate(pipeline);
+ const enabledResult = coll.aggregate(pipeline).toArray();
- // Enable a failpoint that will cause match expression optimizations to be skipped. Test that
- // the expression isn't modified after it's specified.
+ // Enable a failpoint that will cause match expression optimizations to be skipped.
assert.commandWorked(testDb.adminCommand(
{configureFailPoint: "disableMatchExpressionOptimization", mode: "alwaysOn"}));
@@ -39,7 +35,7 @@
assert.eq(getAggPlanStage(disabledPlan, "$cursor").$cursor.queryPlanner.parsedQuery._id.$in,
[kTestZip]);
- const disabledResult = coll.aggregate(pipeline);
+ const disabledResult = coll.aggregate(pipeline).toArray();
// Test that the result is the same with and without optimizations enabled (result is sorted).
assert.eq(enabledResult, disabledResult);
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);