summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-03-03 12:02:10 -0500
committerDavid Storch <david.storch@10gen.com>2016-03-07 10:01:46 -0500
commit49825c02c6b1097da9af977fc25f914d484fa642 (patch)
treeb5a5533fff527f5b8ba72ba00e25345ed4be2678
parente4bd8cef2b34b96f07986d8523333dd3c6b29f1a (diff)
downloadmongo-49825c02c6b1097da9af977fc25f914d484fa642.tar.gz
SERVER-22945 rewrite update_yield1.js to not depend on timing
-rw-r--r--jstests/noPassthrough/update_yield1.js102
1 files changed, 33 insertions, 69 deletions
diff --git a/jstests/noPassthrough/update_yield1.js b/jstests/noPassthrough/update_yield1.js
index 7e04afd8a4a..8a81ccc144b 100644
--- a/jstests/noPassthrough/update_yield1.js
+++ b/jstests/noPassthrough/update_yield1.js
@@ -1,76 +1,40 @@
-load( "jstests/libs/slow_weekly_util.js" );
-var testServer = new SlowWeeklyMongod( "update_yield1" );
-var db = testServer.getDB( "test" );
-testServer.getDB("admin").runCommand( {setParameter:1, ttlMonitorEnabled : false} );
+// Ensure that multi-update operations yield regularly.
+(function() {
+ 'use strict';
-var t = db.update_yield1;
-t.drop();
+ var explain;
+ var yieldCount;
-var N = 640000;
-var i = 0;
+ const nDocsToInsert = 300;
+ const worksPerYield = 50;
-while ( true ){
- var fill = function() {
- var bulk = t.initializeUnorderedBulkOp();
- for ( ; i<N; i++ ){
- bulk.insert({ _id: i, n: 1 });
- }
- assert.writeOK(bulk.execute());
- };
+ // Start a mongod that will yield every 50 work cycles.
+ var mongod = MongoRunner.runMongod({
+ setParameter: `internalQueryExecYieldIterations=${worksPerYield}`
+ });
+ assert.neq(null, mongod, 'mongod was unable to start up');
- var timeUpdate = function() {
- return Date.timeFunc(
- function(){
- t.update( {} , { $inc : { n : 1 } } , false , true );
- }
- );
- };
+ var coll = mongod.getDB('test').update_yield1;
+ coll.drop();
- fill();
- timeUpdate();
- timeUpdate();
- var time = timeUpdate();
- print( N + "\t" + time );
- if ( time > 8000 )
- break;
-
- N *= 2;
-}
-
-function haveInProgressUpdate() {
- var ops = db.currentOp();
- printjson(ops);
- return ops.inprog.some(
- function(elt) {
- return elt.op == "update";
- });
-}
-
-// --- test 1
-
-var join = startParallelShell( "db.update_yield1.update( {}, { $inc: { n: 1 }}, false, true );" );
-assert.soon(haveInProgressUpdate, "never doing update");
-
-var num = 0;
-var start = new Date();
-while ( ( (new Date()).getTime() - start ) < ( time * 2 ) ){
- var me = Date.timeFunc( function(){ t.findOne(); } );
- if (me > 50) print("time: " + me);
-
- if ( num++ == 0 ){
- var x = db.currentOp();
- // one operation for the update, another for currentOp itself. There may be other internal
- // operations running.
- assert.lte( 2 , x.inprog.length , "nothing in prog" );
+ for (var i = 0; i < nDocsToInsert; i++) {
+ assert.writeOK(coll.insert({_id: i}));
}
- assert.gt( time / 3 , me );
-}
-
-join();
-
-var curOp = db.currentOp();
-// currentOp itself shows up as an active operation
-assert.eq( 1 , curOp.inprog.length , tojson(curOp) );
-
-testServer.stop();
+ // A multi-update doing a collection scan should yield about nDocsToInsert / worksPerYield
+ // times.
+ explain = coll.explain('executionStats').update({}, {$inc: {counter: 1}}, {multi: true});
+ assert.commandWorked(explain);
+ yieldCount = explain.executionStats.executionStages.saveState;
+ assert.gt(yieldCount, (nDocsToInsert / worksPerYield) - 2);
+
+ // A multi-update shouldn't yield if it has $isolated.
+ explain = coll.explain('executionStats').update(
+ {$isolated: true},
+ {$inc: {counter: 1}},
+ {multi: true}
+ );
+ assert.commandWorked(explain);
+ yieldCount = explain.executionStats.executionStages.saveState;
+ assert.eq(yieldCount, 0, 'yielded during $isolated multi-update');
+})();