2012-12-12 01:36:58 +01:00
|
|
|
/**
|
|
|
|
* Test to make sure that commands that should only work when testing commands are enabled
|
|
|
|
* via the --enableTestCommands flag fail when that flag isn't provided.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var testOnlyCommands = ['_testDistLockWithSyncCluster',
|
|
|
|
'_testDistLockWithSkew',
|
|
|
|
'_skewClockCommand',
|
|
|
|
'configureFailPoint',
|
|
|
|
'_hashBSONElement',
|
|
|
|
'replSetTest',
|
|
|
|
'journalLatencyTest',
|
|
|
|
'godinsert',
|
|
|
|
'sleep',
|
|
|
|
'captrunc',
|
|
|
|
'emptycapped']
|
|
|
|
|
|
|
|
var assertCmdNotFound = function(db, cmdName) {
|
|
|
|
var res = db.runCommand(cmdName);
|
|
|
|
assert.eq(0, res.ok);
|
2014-11-13 16:51:20 +01:00
|
|
|
assert.eq(59, res.code, 'expected CommandNotFound(59) error code for test command ' + cmdName);
|
2012-12-12 01:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var assertCmdFound = function(db, cmdName) {
|
|
|
|
var res = db.runCommand(cmdName);
|
2014-11-13 16:51:20 +01:00
|
|
|
if (!res.ok) {
|
|
|
|
assert.neq(59, res.code,
|
|
|
|
'test command ' + cmdName + ' should either have succeeded or ' +
|
|
|
|
'failed with an error code other than CommandNotFound(59)');
|
|
|
|
}
|
2012-12-12 01:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
jsTest.setOption('enableTestCommands', false);
|
|
|
|
|
2012-12-18 20:34:46 +01:00
|
|
|
var conn = startMongodTest();
|
2012-12-12 01:36:58 +01:00
|
|
|
for (i in testOnlyCommands) {
|
|
|
|
assertCmdNotFound(conn.getDB('test'), testOnlyCommands[i]);
|
|
|
|
}
|
|
|
|
MongoRunner.stopMongod(conn.port);
|
|
|
|
|
|
|
|
// Now enable the commands
|
|
|
|
jsTest.setOption('enableTestCommands', true);
|
|
|
|
|
2012-12-18 20:34:46 +01:00
|
|
|
var conn = startMongodTest();
|
2012-12-12 01:36:58 +01:00
|
|
|
for (i in testOnlyCommands) {
|
|
|
|
assertCmdFound(conn.getDB('test'), testOnlyCommands[i]);
|
|
|
|
}
|
|
|
|
MongoRunner.stopMongod(conn.port);
|