Skip to content

Commit

Permalink
Merge 7c3771a into d96806c
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 16, 2016
2 parents d96806c + 7c3771a commit 6948284
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 81 deletions.
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ environment:
- nodejs_version: '5'
- nodejs_version: '4'
- nodejs_version: '0.12'
- nodejs_version: '0.10'
install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
Expand Down
26 changes: 15 additions & 11 deletions signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// fatal signal like SIGWINCH or something, and then
// exit, it'll end up firing `process.emit('exit')`, so
// the handler will be fired anyway.

module.exports = [
'SIGABRT',
'SIGALRM',
Expand All @@ -22,19 +21,24 @@ module.exports = [
'SIGHUP',
'SIGILL',
'SIGINT',
'SIGIOT',
'SIGPROF',
'SIGQUIT',
'SIGSEGV',
'SIGSYS',
'SIGTERM',
'SIGTRAP',
'SIGUSR2',
'SIGVTALRM',
'SIGXCPU',
'SIGXFSZ'
'SIGTERM'
]

if (process.platform !== 'win32') {
module.exports.push(
'SIGVTALRM',
'SIGXCPU',
'SIGXFSZ',
'SIGUSR2',
'SIGTRAP',
'SIGSYS',
'SIGQUIT',
'SIGIOT',
'SIGPROF'
)
}

if (process.platform === 'linux') {
module.exports.push(
'SIGIO',
Expand Down
22 changes: 12 additions & 10 deletions test/all-integration-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* global describe, it */

var exec = require('child_process').exec,
assert = require('assert'),
shell = process.platform === 'win32' ? null : { shell: '/bin/bash' }
var exec = require('child_process').exec
var assert = require('assert')
var isWindows = process.platform === 'win32'
var shell = isWindows ? null : { shell: '/bin/bash' }
var node = isWindows ? '"' + process.execPath + '"' : process.execPath

require('chai').should()
require('tap').mochaGlobals()
Expand All @@ -25,9 +27,10 @@ describe('all-signals-integration-test', function () {
}

// Exhaustively test every signal, and a few numbers.
var signals = onSignalExit.signals()
// signal-exit does not currently support process.kill()
// on win32.
var signals = isWindows ? [] : onSignalExit.signals()
signals.concat('', 0, 1, 2, 3, 54).forEach(function (sig) {
var node = process.execPath
var js = require.resolve('./fixtures/exiter.js')
it('exits properly: ' + sig, function (done) {
// issues with SIGUSR1 on Node 0.10.x
Expand All @@ -36,13 +39,13 @@ describe('all-signals-integration-test', function () {
var cmd = node + ' ' + js + ' ' + sig
exec(cmd, shell, function (err, stdout, stderr) {
if (sig) {
assert(err)
if (!isWindows) assert(err)
if (!isNaN(sig)) {
assert.equal(err.code, sig)
if (!isWindows) assert.equal(err.code, sig)
} else if (!weirdSignal(sig)) {
err.signal.should.equal(sig)
if (!isWindows) err.signal.should.equal(sig)
} else if (sig) {
assert(err.signal)
if (!isWindows) assert(err.signal)
}
} else {
assert.ifError(err)
Expand All @@ -66,7 +69,6 @@ describe('all-signals-integration-test', function () {
})

signals.forEach(function (sig) {
var node = process.execPath
var js = require.resolve('./fixtures/parent.js')
it('exits properly: (external sig) ' + sig, function (done) {
// issues with SIGUSR1 on Node 0.10.x
Expand Down
10 changes: 6 additions & 4 deletions test/multi-exit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var exec = require('child_process').exec,
t = require('tap'),
shell = process.platform === 'win32' ? null : { shell: '/bin/bash' }
var exec = require('child_process').exec
var t = require('tap')
var isWindows = process.platform === 'win32'
var shell = isWindows ? null : { shell: '/bin/bash' }
var node = isWindows ? '"' + process.execPath + '"' : process.execPath

var fixture = require.resolve('./fixtures/change-code.js')
var expect = require('./fixtures/change-code-expect.json')
Expand Down Expand Up @@ -41,7 +43,7 @@ types.forEach(function (type) {

opts.forEach(function (opt) {
t.test(opt, function (t) {
var cmd = process.execPath + ' ' + fixture + ' ' + opt
var cmd = node + ' ' + fixture + ' ' + opt
exec(cmd, shell, function (err, stdout, stderr) {
var res = JSON.parse(stdout)
if (err) {
Expand Down
113 changes: 58 additions & 55 deletions test/signal-exit-test.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
/* global describe, it */

var exec = require('child_process').exec,
expect = require('chai').expect,
assert = require('assert'),
shell = process.platform === 'win32' ? null : { shell: '/bin/bash' }
var exec = require('child_process').exec
var expect = require('chai').expect
var assert = require('assert')
var isWindows = process.platform === 'win32'
var shell = isWindows ? null : { shell: '/bin/bash' }
var node = isWindows ? '"' + process.execPath + '"' : process.execPath

require('chai').should()
require('tap').mochaGlobals()

describe('signal-exit', function () {

it('receives an exit event when a process exits normally', function (done) {
exec(process.execPath + ' ./test/fixtures/end-of-execution.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/end-of-execution.js', shell, function (err, stdout, stderr) {
expect(err).to.equal(null)
stdout.should.match(/reached end of execution, 0, null/)
done()
})
})

it('receives an exit event when a process is terminated with sigint', function (done) {
exec(process.execPath + ' ./test/fixtures/sigint.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigint, null, SIGINT/)
done()
})
})

it('receives an exit event when a process is terminated with sigterm', function (done) {
exec(process.execPath + ' ./test/fixtures/sigterm.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigterm, null, SIGTERM/)
done()
})
})

it('receives an exit event when process.exit() is called', function (done) {
exec(process.execPath + ' ./test/fixtures/exit.js', shell, function (err, stdout, stderr) {
err.code.should.equal(32)
exec(node + ' ./test/fixtures/exit.js', shell, function (err, stdout, stderr) {
if (!isWindows) err.code.should.equal(32)
stdout.should.match(/exited with process\.exit\(\), 32, null/)
done()
})
})

it('does not exit if user handles signal', function (done) {
exec(process.execPath + ' ./test/fixtures/signal-listener.js', shell, function (err, stdout, stderr) {
assert(err)
assert.equal(stdout, 'exited calledListener=4, code=null, signal="SIGHUP"\n')
done()
})
})

it('ensures that if alwaysLast=true, the handler is run last (signal)', function (done) {
exec(process.execPath + ' ./test/fixtures/signal-last.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/signal-last.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/first counter=1/)
stdout.should.match(/last counter=2/)
Expand All @@ -60,7 +38,7 @@ describe('signal-exit', function () {
})

it('ensures that if alwaysLast=true, the handler is run last (normal exit)', function (done) {
exec(process.execPath + ' ./test/fixtures/exit-last.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/exit-last.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
stdout.should.match(/first counter=1/)
stdout.should.match(/last counter=2/)
Expand All @@ -69,46 +47,71 @@ describe('signal-exit', function () {
})

it('works when loaded multiple times', function (done) {
exec(process.execPath + ' ./test/fixtures/multiple-load.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/multiple-load.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/first counter=1, code=null, signal="SIGHUP"/)
stdout.should.match(/first counter=2, code=null, signal="SIGHUP"/)
stdout.should.match(/last counter=3, code=null, signal="SIGHUP"/)
stdout.should.match(/last counter=4, code=null, signal="SIGHUP"/)
stdout.should.match(/first counter=1/)
stdout.should.match(/first counter=2/)
stdout.should.match(/last counter=3/)
stdout.should.match(/last counter=4/)
done()
})
})

// TODO: test on a few non-OSX machines.
it('removes handlers when fully unwrapped', function (done) {
exec(process.execPath + ' ./test/fixtures/unwrap.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/unwrap.js', shell, function (err, stdout, stderr) {
assert(err)
err.signal.should.equal('SIGHUP')
expect(err.code).to.equal(null)
if (!isWindows) err.signal.should.equal('SIGHUP')
if (!isWindows) expect(err.code).to.equal(null)
done()
})
})

it('does not load() or unload() more than once', function (done) {
exec(process.execPath + ' ./test/fixtures/load-unload.js', shell, function (err, stdout, stderr) {
exec(node + ' ./test/fixtures/load-unload.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
done()
})
})

it('handles uncatchable signals with grace and poise', function (done) {
exec(process.execPath + ' ./test/fixtures/sigkill.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
done()
if (!isWindows) {
it('receives an exit event when a process is terminated with sigint', function (done) {
exec(node + ' ./test/fixtures/sigint.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigint, null, SIGINT/)
done()
})
})
})

it('does not exit on sigpipe', function (done) {
exec(process.execPath + ' ./test/fixtures/sigpipe.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
stdout.should.match(/hello/)
stderr.should.match(/onSignalExit\(0,null\)/)
done()
it('receives an exit event when a process is terminated with sigterm', function (done) {
exec(node + ' ./test/fixtures/sigterm.js', shell, function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigterm, null, SIGTERM/)
done()
})
})
})

it('does not exit on sigpipe', function (done) {
exec(node + ' ./test/fixtures/sigpipe.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
stdout.should.match(/hello/)
stderr.should.match(/onSignalExit\(0,null\)/)
done()
})
})

it('handles uncatchable signals with grace and poise', function (done) {
exec(node + ' ./test/fixtures/sigkill.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
done()
})
})

it('does not exit if user handles signal', function (done) {
exec(node + ' ./test/fixtures/signal-listener.js', shell, function (err, stdout, stderr) {
assert(err)
assert.equal(stdout, 'exited calledListener=4, code=null, signal="SIGHUP"\n')
done()
})
})
}
})

0 comments on commit 6948284

Please sign in to comment.