summaryrefslogtreecommitdiff
path: root/jstests/cursora.js
blob: a46688a71472d00f4dbd5fa4f56e5795614fc244 (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
t = db.cursora

function run( n , atomic ){
    if( !isNumber(n) ) {
	print("n:");
	printjson(n);
	assert(isNumber(n), "cursora.js isNumber");
    }
    t.drop()
    
    for ( i=0; i<n; i++ )
        t.insert( { _id : i } )
    db.getLastError()

    print("cursora.js startParallelShell n:"+n+" atomic:"+atomic)
    join = startParallelShell( "sleep(50); db.cursora.remove( {"  + ( atomic ? "$atomic:true" : "" ) + "} ); db.getLastError();" );

    var start = null;
    var ex = null;
    var num = null;
    var end = null;
    try {
        start = new Date()
        ex = t.find(function () { num = 2; for (var x = 0; x < 1000; x++) num += 2; return num > 0; }).sort({ _id: -1 }).explain()
        num = ex.n
        end = new Date()
    }
    catch (e) {
        print("cursora.js FAIL " + e);
        join();
        throw e;
    }
    
    join()

    //print( "cursora.js num: " + num + " time:" + ( end.getTime() - start.getTime() ) )
    assert.eq( 0 , t.count() , "after remove: " + tojson( ex ) )
    // assert.lt( 0 , ex.nYields , "not enough yields : " + tojson( ex ) ); // TODO make this more reliable so cen re-enable assert
    if ( n == num )
        print( "cursora.js warning: shouldn't have counted all  n: " + n + " num: " + num );
}

run( 1500 )
run( 5000 )
run( 1500 , true )
run( 5000 , true )
print("cursora.js SUCCESS")