summaryrefslogtreecommitdiff
path: root/jstests/core/drop2.js
blob: f0dee81b592c31bd05212fe6207e8f71ff99e67f (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
var coll = db.jstests_drop2;
coll.drop();

function debug( x ) {
    printjson( x );
}

coll.save( {} );

function getOpId( drop ) {
    var inProg = db.currentOp().inprog;
    debug( inProg );
    for ( var id in inProg ) {
        var op = inProg[ id ];
        if ( drop ) {
            if (  op.query && op.query.drop && op.query.drop == coll.getName() ) {
                return op.opid;
            }
        } else {
            if (  op.query && op.query.query && op.query.query.$where && op.ns == (coll + "") ) {
                return op.opid;
            }
        }
    }
    return null;
}

var awaitCount = startParallelShell( "print(\"Count thread started\");"
                                     + "db.getMongo().getCollection(\""
                                     + (coll + "") + "\")"
                                     + ".count( { $where: function() {"
                                     + "while( 1 ) { sleep( 1 ); } } } );"
                                     + "print(\"Count thread terminating\");" );
countOpId = null;
assert.soon( function() { countOpId = getOpId( false ); return countOpId; } );

var awaitDrop = startParallelShell( "print(\"Drop thread started\");"
                                    + "print(\"drop result: \" + "
                                    + "db.getMongo().getCollection(\""
                                    + (coll + "") + "\")"
                                    + ".drop() );"
                                    + "print(\"Drop thread terminating\")" );
dropOpId = null;
assert.soon( function() { dropOpId = getOpId( true ); return dropOpId; } );

db.killOp( dropOpId );
db.killOp( countOpId );

var exitCode = awaitCount({checkExitSuccess: false});
assert.neq(0, exitCode, "expected shell to exit abnormally due to JS execution being terminated");

// The drop operation may or may not have been killed.
awaitDrop({checkExitSuccess: false});

coll.drop(); // in SERVER-1818, this fails