diff options
Diffstat (limited to 'jstests/noPassthrough/exit_logging.js')
-rw-r--r-- | jstests/noPassthrough/exit_logging.js | 185 |
1 files changed, 92 insertions, 93 deletions
diff --git a/jstests/noPassthrough/exit_logging.js b/jstests/noPassthrough/exit_logging.js index 4e6be5c811f..168f63a4579 100644 --- a/jstests/noPassthrough/exit_logging.js +++ b/jstests/noPassthrough/exit_logging.js @@ -5,105 +5,104 @@ (function() { - function makeShutdownByCrashFn(crashHow) { - return function(conn) { - var admin = conn.getDB("admin"); - assert.commandWorked(admin.runCommand( - {configureFailPoint: "crashOnShutdown", mode: "alwaysOn", data: {how: crashHow}})); - admin.shutdownServer(); - }; - } - - function makeRegExMatchFn(pattern) { - return function(text) { - return pattern.test(text); - }; - } - - function testShutdownLogging(launcher, crashFn, matchFn, expectedExitCode) { - clearRawMongoProgramOutput(); - var conn = launcher.start({}); - - function checkOutput() { - var logContents = rawMongoProgramOutput(); - function printLog() { - // We can't just return a string because it will be well over the max - // line length. - // So we just print manually. - print("================ BEGIN LOG CONTENTS =================="); - logContents.split(/\n/).forEach((line) => { - print(line); - }); - print("================ END LOG CONTENTS ====================="); - return ""; - } - - assert(matchFn(logContents), printLog); +function makeShutdownByCrashFn(crashHow) { + return function(conn) { + var admin = conn.getDB("admin"); + assert.commandWorked(admin.runCommand( + {configureFailPoint: "crashOnShutdown", mode: "alwaysOn", data: {how: crashHow}})); + admin.shutdownServer(); + }; +} + +function makeRegExMatchFn(pattern) { + return function(text) { + return pattern.test(text); + }; +} + +function testShutdownLogging(launcher, crashFn, matchFn, expectedExitCode) { + clearRawMongoProgramOutput(); + var conn = launcher.start({}); + + function checkOutput() { + var logContents = rawMongoProgramOutput(); + function printLog() { + // We can't just return a string because it will be well over the max + // line length. + // So we just print manually. + print("================ BEGIN LOG CONTENTS =================="); + logContents.split(/\n/).forEach((line) => { + print(line); + }); + print("================ END LOG CONTENTS ====================="); + return ""; } - crashFn(conn); - launcher.stop(conn, undefined, {allowedExitCode: expectedExitCode}); - checkOutput(); - } - - function runAllTests(launcher) { - const SIGSEGV = 11; - const SIGABRT = 6; - testShutdownLogging(launcher, function(conn) { - conn.getDB('admin').shutdownServer(); - }, makeRegExMatchFn(/shutdown command received/), MongoRunner.EXIT_CLEAN); - - testShutdownLogging(launcher, - makeShutdownByCrashFn('fault'), - makeRegExMatchFn(/Invalid access at address[\s\S]*printStackTrace/), - -SIGSEGV); - - testShutdownLogging(launcher, - makeShutdownByCrashFn('abort'), - makeRegExMatchFn(/Got signal[\s\S]*printStackTrace/), - -SIGABRT); - } - - if (_isWindows()) { - print("SKIPPING TEST ON WINDOWS"); - return; + assert(matchFn(logContents), printLog); } - if (_isAddressSanitizerActive()) { - print("SKIPPING TEST ON ADDRESS SANITIZER BUILD"); - return; - } - - (function testMongod() { - print("********************\nTesting exit logging in mongod\n********************"); - - runAllTests({ - start: function(opts) { - var actualOpts = {nojournal: ""}; - Object.extend(actualOpts, opts); - return MongoRunner.runMongod(actualOpts); - }, - - stop: MongoRunner.stopMongod - }); - }()); - - (function testMongos() { - print("********************\nTesting exit logging in mongos\n********************"); + crashFn(conn); + launcher.stop(conn, undefined, {allowedExitCode: expectedExitCode}); + checkOutput(); +} + +function runAllTests(launcher) { + const SIGSEGV = 11; + const SIGABRT = 6; + testShutdownLogging(launcher, function(conn) { + conn.getDB('admin').shutdownServer(); + }, makeRegExMatchFn(/shutdown command received/), MongoRunner.EXIT_CLEAN); + + testShutdownLogging(launcher, + makeShutdownByCrashFn('fault'), + makeRegExMatchFn(/Invalid access at address[\s\S]*printStackTrace/), + -SIGSEGV); + + testShutdownLogging(launcher, + makeShutdownByCrashFn('abort'), + makeRegExMatchFn(/Got signal[\s\S]*printStackTrace/), + -SIGABRT); +} + +if (_isWindows()) { + print("SKIPPING TEST ON WINDOWS"); + return; +} + +if (_isAddressSanitizerActive()) { + print("SKIPPING TEST ON ADDRESS SANITIZER BUILD"); + return; +} + +(function testMongod() { + print("********************\nTesting exit logging in mongod\n********************"); + + runAllTests({ + start: function(opts) { + var actualOpts = {nojournal: ""}; + Object.extend(actualOpts, opts); + return MongoRunner.runMongod(actualOpts); + }, + + stop: MongoRunner.stopMongod + }); +}()); - var st = new ShardingTest({shards: 1}); - var mongosLauncher = { - start: function(opts) { - var actualOpts = {configdb: st._configDB}; - Object.extend(actualOpts, opts); - return MongoRunner.runMongos(actualOpts); - }, +(function testMongos() { + print("********************\nTesting exit logging in mongos\n********************"); - stop: MongoRunner.stopMongos - }; + var st = new ShardingTest({shards: 1}); + var mongosLauncher = { + start: function(opts) { + var actualOpts = {configdb: st._configDB}; + Object.extend(actualOpts, opts); + return MongoRunner.runMongos(actualOpts); + }, - runAllTests(mongosLauncher); - st.stop(); - }()); + stop: MongoRunner.stopMongos + }; + runAllTests(mongosLauncher); + st.stop(); +}()); }()); |