summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/update_yield1.js
blob: ecca2fc4e50bd7caf66ce66ecd96cadf1faded59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SERVER-13922
if (0) {

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} );

var t = db.update_yield1;
t.drop();

var N = 640000;
var i = 0;

while ( true ){
    var fill = function() {
        var bulk = t.initializeUnorderedBulkOp();
        for ( ; i<N; i++ ){
            bulk.insert({ _id: i, n: 1 });
        }
        assert.writeOK(bulk.execute());
    };

    var timeUpdate = function() {
        return Date.timeFunc(
            function(){
                t.update( {} , { $inc : { n : 1 } } , false , true );
            }
        );
    };

    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();
        assert.eq( 1 , x.inprog.length , "nothing in prog" );
    }

    assert.gt( time / 3 , me );
}

join();

x = db.currentOp();
assert.eq( 0 , x.inprog.length , "weird 2" );

testServer.stop();

}  // if (0)