From 6f2cc6be2d10a0b831ce6a721602b782f920f3ee Mon Sep 17 00:00:00 2001 From: Glenn Murray Date: Tue, 4 Mar 2014 15:33:44 +1100 Subject: [PATCH] Graceful termination failing test for #97 and #73 Will fail if any timers or callbacks remain registered when instantiating a logger with a rotating file. --- test/process-exit.js | 11 +++++++++++ test/process-exit.test.js | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/process-exit.js create mode 100644 test/process-exit.test.js diff --git a/test/process-exit.js b/test/process-exit.js new file mode 100644 index 0000000..5e547c9 --- /dev/null +++ b/test/process-exit.js @@ -0,0 +1,11 @@ +var bunyan = require('../lib/bunyan'); +var log = bunyan.createLogger({ + name: 'default', + streams: [{ + type: 'rotating-file', + path: __dirname + '/log.test.rot.log', + period: '1d', + count: 7 + }] +}); +console.log('done'); \ No newline at end of file diff --git a/test/process-exit.test.js b/test/process-exit.test.js new file mode 100644 index 0000000..954cf46 --- /dev/null +++ b/test/process-exit.test.js @@ -0,0 +1,21 @@ +'use strict'; +/* + * Test that bunyan process will terminate + */ + +var exec = require('child_process').exec; + +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var test = tap4nodeunit.test; + +test('log with rotating file stream will terminate gracefully', function (t) { + exec('node ' +__dirname + '/process-exit.js', {timeout: 1000}, function(err, stdout, stderr) { + t.ifError(err); + t.equal(stdout, 'done\n'); + t.equal(stderr, ''); + t.end(); + }); +}); \ No newline at end of file