diff options
author | Jason Rassi <rassi@10gen.com> | 2015-11-20 12:13:37 -0500 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-11-20 16:57:33 -0500 |
commit | 28b2447052b24d77f628c10be68a5ed69a276610 (patch) | |
tree | eb5d15612dcd1a17f88e5ea3f2b14fd5e3a83299 /jstests/noPassthrough/query_yield_reset_timer.js | |
parent | 463993d94b20b130c8dd1523da5688a561c07862 (diff) | |
download | mongo-28b2447052b24d77f628c10be68a5ed69a276610.tar.gz |
SERVER-21341 Add regression test query_yield_reset_timer.js
Diffstat (limited to 'jstests/noPassthrough/query_yield_reset_timer.js')
-rw-r--r-- | jstests/noPassthrough/query_yield_reset_timer.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/jstests/noPassthrough/query_yield_reset_timer.js b/jstests/noPassthrough/query_yield_reset_timer.js new file mode 100644 index 00000000000..8d2e26cc9e5 --- /dev/null +++ b/jstests/noPassthrough/query_yield_reset_timer.js @@ -0,0 +1,46 @@ +// Tests the reset logic for the periodic query yield timer. Regression test for SERVER-21341. +(function() { + 'use strict'; + var dbpath = MongoRunner.dataPath + jsTest.name(); + resetDbpath(dbpath); + var mongod = MongoRunner.runMongod({dbpath: dbpath}); + var coll = mongod.getDB("test").getCollection(jsTest.name()); + + // Configure the server so that queries are expected to yield after every 10 work cycles, or + // after every 500 milliseconds (whichever comes first). In addition, enable a failpoint that + // introduces a sleep delay of 1 second during each yield. + assert.commandWorked(coll.getDB().adminCommand({setParameter: 1, + internalQueryExecYieldIterations: 10})); + assert.commandWorked(coll.getDB().adminCommand({setParameter: 1, + internalQueryExecYieldPeriodMS: 500})); + assert.commandWorked(coll.getDB().adminCommand({configureFailPoint: "setYieldAllLocksWait", + namespace: coll.getFullName(), + mode: "alwaysOn", + data: {waitForMillis: 1000}})); + + // Insert 40 documents in the collection, perform a collection scan, and verify that it yields + // about 4 times. Since each group of 10 documents should always be processed in less than 500 + // milliseconds, we expect to hit only iteration-based yields for this query, and no + // timing-based yields. 40 documents total divided by 10 documents per yield gives us an + // estimated yield count of 4 yields. + // + // Note also that we have a 1-second sleep delay during each yield, and we expect this delay to + // not change our expectation to hit zero timing-based yields. Timing-based yields only consider + // time spent during query execution since the last yield; since our sleep delay of 1 second is + // not during query execution, it should never count towards our 500 millisecond threshold for a + // timing-based yield (incorrect accounting for timing-based yields was the cause for + // SERVER-21341). + for (var i=0; i<40; ++i) { + assert.writeOK(coll.insert({})); + } + var explainRes = coll.find().explain("executionStats"); + // We expect 4 yields, but we throw in a fudge factor of 2 for test reliability. We also can + // use "saveState" calls as a proxy for "number of yields" here, because we expect our entire + // result set to be returned in a single batch. + assert.gt(explainRes.executionStats.executionStages.saveState, + 4 / 2, + tojson(explainRes)); + assert.lt(explainRes.executionStats.executionStages.saveState, + 4 * 2, + tojson(explainRes)); +})(); |