Files
mongo/jstests/shellkillop.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2011-01-01 21:37:31 -05:00
baseName = "jstests_shellkillop";
2011-01-01 18:19:40 -05:00
2011-01-18 10:55:23 -08:00
// 'retry' should be set to true in contexts where an exception should cause the test to be retried rather than to fail.
2011-01-18 21:34:06 -08:00
retry = false;
2011-01-18 10:55:23 -08:00
function testShellAutokillop() {
2011-01-01 21:37:31 -05:00
if (_isWindows()) {
print("shellkillop.js not testing on windows, as functionality is missing there");
print("shellkillop.js see http://jira.mongodb.org/browse/SERVER-1451");
}
else {
db[baseName].drop();
2011-01-01 18:19:40 -05:00
2011-01-01 21:37:31 -05:00
print("shellkillop.js insert data");
for (i = 0; i < 100000; ++i) {
db[baseName].insert({ i: 1 });
}
assert.eq(100000, db[baseName].count());
2011-01-01 18:19:40 -05:00
2011-01-01 21:37:31 -05:00
// mongo --autokillop suppressed the ctrl-c "do you want to kill current operation" message
// it's just for testing purposes and thus not in the shell help
var evalStr = "print('SKO subtask started'); db." + baseName + ".update( {}, {$set:{i:'abcdefghijkl'}}, false, true ); db." + baseName + ".count();";
print("shellkillop.js evalStr:" + evalStr);
spawn = startMongoProgramNoConnect("mongo", "--autokillop", "--port", myPort(), "--eval", evalStr);
sleep(100);
2011-01-18 10:55:23 -08:00
retry = true;
2011-01-01 21:37:31 -05:00
assert(db[baseName].find({ i: 'abcdefghijkl' }).count() < 100000, "update ran too fast, test won't be valid");
2011-01-18 10:55:23 -08:00
retry = false;
2011-01-01 21:37:31 -05:00
stopMongoProgramByPid(spawn);
2011-01-03 01:01:11 -05:00
sleep(100);
2011-01-01 21:37:31 -05:00
print("count abcdefghijkl:" + db[baseName].find({ i: 'abcdefghijkl' }).count());
2011-01-03 01:01:11 -05:00
var inprog = db.currentOp().inprog;
for (i in inprog) {
if (inprog[i].ns == "test." + baseName)
throw "shellkillop.js op is still running: " + tojson( inprog[i] );
}
2011-01-01 21:37:31 -05:00
2011-01-18 10:55:23 -08:00
retry = true;
2011-01-03 01:01:11 -05:00
assert(db[baseName].find({ i: 'abcdefghijkl' }).count() < 100000, "update ran too fast, test was not valid");
2011-01-18 10:55:23 -08:00
retry = false;
}
}
2011-01-03 01:01:11 -05:00
2011-01-18 10:55:23 -08:00
for( var nTries = 0; nTries < 10 && retry; ++nTries ) {
try {
testShellAutokillop();
} catch (e) {
if ( !retry ) {
throw e;
}
printjson( e );
print( "retrying..." );
}
2011-01-01 18:19:40 -05:00
}
2011-01-18 10:55:23 -08:00
assert( !retry, "retried too many times" );
print("shellkillop.js SUCCESS");