File: killall.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (57 lines) | stat: -rw-r--r-- 2,360 bytes parent folder | download | duplicates (3)
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
/*
 * Verify that killing an instance of mongod while it is in a long running computation or infinite
 * loop still leads to clean shutdown, and that said shutdown is prompt.
 *
 * For our purposes, "prompt" is defined as "before stopMongod() decides to send a SIGKILL" and also
 * "before mongod starts executing the next pending operation after the currently executing one."
 *
 * This is also a regression test for SERVER-1818.  By queuing up a collection drop behind an
 * infinitely looping operation, we ensure that killall interrupts the drop command (drop is
 * normally a short lived operation and is otherwise difficult to kill deterministically).  The
 * subsequent drop() on restart would historically assert if the data integrity issue caused by
 * SERVER-1818 occured.
 */

port = allocatePorts( 1 )[ 0 ]

var baseName = "jstests_disk_killall";
var dbpath = "/data/db/" + baseName;

var mongod = startMongod( "--port", port, "--dbpath", dbpath, "--nohttpinterface" );
var db = mongod.getDB( "test" );
var collection = db.getCollection( baseName );

collection.save( {} );
assert( ! db.getLastError() );

s1 = startParallelShell( "db." + baseName + ".count( { $where: function() { while( 1 ) { ; } } } )", port );
// HACK(schwerin): startParallelShell's return value should allow you to block until the command has
// started, for some definition of started.
sleep( 1000 );

s2 = startParallelShell( "db." + baseName + ".drop()", port );
sleep( 1000 );  // HACK(schwerin): See above.

/**
 * 0 == mongod's exit code on Windows, or when it receives TERM, HUP or INT signals.  On UNIX
 * variants, stopMongod sends a TERM signal to mongod, then waits for mongod to stop.  If mongod
 * doesn't stop in a reasonable amount of time, stopMongod sends a KILL signal, in which case mongod
 * will not exit cleanly.  We're checking in this assert that mongod will stop quickly even while
 * evaling an infinite loop in server side js.
 *
 * NOTE: 14 is sometimes returned instead due to SERVER-2652.
 */
var exitCode = stopMongod( port );
assert( exitCode in [0, 14], "got unexpected exitCode: " + exitCode );

s1();
s2();

mongod = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath );
db = mongod.getDB( "test" );
collection = db.getCollection( baseName );

assert( collection.stats().ok );
assert( collection.drop() );

stopMongod( port );