summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-07-30 10:05:06 -0400
committerDan Pasette <dan@mongodb.com>2014-07-30 23:26:27 -0400
commit0716e2c0158306dbf75408d980c35cb23b829017 (patch)
tree17f0bdbab97e9d6ac426ece85e621d9799d84450
parent1a0a49598d036c68c111cd04ac48655437dd6f83 (diff)
downloadmongo-0716e2c0158306dbf75408d980c35cb23b829017.tar.gz
SERVER-14731 print more debug info when plan_cache_ties.js fails
(cherry picked from commit 791e2e00806449a01e7dec4d9b969392e183f393)
-rw-r--r--jstests/core/plan_cache_ties.js40
1 files changed, 36 insertions, 4 deletions
diff --git a/jstests/core/plan_cache_ties.js b/jstests/core/plan_cache_ties.js
index edb16c0b18b..70c69925a91 100644
--- a/jstests/core/plan_cache_ties.js
+++ b/jstests/core/plan_cache_ties.js
@@ -3,6 +3,23 @@
var t = db.jstests_plan_cache_ties;
t.drop();
+var shapes;
+
+// Generates debug info. Used in the case of test failure.
+function dumpPlanCache(shapes) {
+ var outstr = '';
+
+ // For each shape in the cache, get the plan cache entry.
+ for (var i = 0; i < shapes.length; i++) {
+ var shape = shapes[i];
+ var cache = t.getPlanCache();
+ var plans = cache.getPlansByQuery(shape.query, shape.projection, shape.sort);
+ outstr += ('getPlansByQuery() for shape ' + i + ' = ' + tojson(plans) + '\n');
+ }
+
+ return outstr;
+}
+
// Utility function to list query shapes in cache.
function getShapes(collection) {
if (collection == undefined) {
@@ -23,17 +40,29 @@ for (var i = 0; i < 200; i++) {
}
t.save({a: 2, b: 2});
+// Do a full collection scan to pull the whole collection into memory.
+assert.eq(201, t.find().itcount(), 'unexpected number of docs in collection');
+
// A query with zero results that does not hit EOF should not be cached.
assert.eq(0, t.find({c: 0}).itcount(), 'unexpected count');
-assert.eq(0, getShapes().length, 'unexpected number of query shapes in plan cache');
+shapes = getShapes();
+assert.eq(0, shapes.length,
+ 'unexpected number of query shapes in plan cache\n'
+ + dumpPlanCache(shapes));
// A query that hits EOF but still results in a tie should not be cached.
assert.eq(0, t.find({a: 3, b: 3}).itcount(), 'unexpected count');
-assert.eq(0, getShapes().length, 'unexpected number of query shapes in plan cache');
+shapes = getShapes()
+assert.eq(0, shapes.length,
+ 'unexpected number of query shapes in plan cache\n'
+ + dumpPlanCache(shapes));
// A query that returns results but leads to a tie should not be cached.
assert.eq(1, t.find({a: 2, b: 2}).itcount(), 'unexpected count');
-assert.eq(0, getShapes().length, 'unexpected number of query shapes in plan cache');
+shapes = getShapes();
+assert.eq(0, shapes.length,
+ 'unexpected number of query shapes in plan cache\n'
+ + dumpPlanCache(shapes));
// With a new index and tweaked data, we deliver a new query that should not tie. Check that
// this one gets cached.
@@ -44,4 +73,7 @@ for (var i = 0; i < 3; i++) {
}
assert.eq(1, t.find({a: 2, b: 2}).itcount(), 'unexpected count');
-assert.eq(1, getShapes().length, 'unexpected number of query shapes in plan cache');
+shapes = getShapes();
+assert.eq(1, shapes.length,
+ 'unexpected number of query shapes in plan cache\n'
+ + dumpPlanCache(shapes));