Skip to content

Commit

Permalink
Exit with SIGTERM when there's a timeout SIGTERM
Browse files Browse the repository at this point in the history
Also, ignore in coverage, since it happens after nyc, and thus can't be
covered.
  • Loading branch information
isaacs committed Jan 25, 2017
1 parent 7510a6d commit 9bb81dc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lib/tap.js
Expand Up @@ -67,8 +67,9 @@ tap.synonyms = require('./synonyms.js')

// SIGTERM means being forcibly killed, almost always by timeout
var onExit = require('signal-exit')
var didTimeoutKill = false
onExit(function (code, signal) {
if (signal !== 'SIGTERM' || !didPipe)
if (signal !== 'SIGTERM' || !didPipe || didTimeoutKill)
return

var handles = process._getActiveHandles().filter(function (h) {
Expand Down Expand Up @@ -113,6 +114,9 @@ onExit(function (code, signal) {
})
}

// this is impossible to cover, because it happens after nyc has
// already done its stuff.
/* istanbul ignore else */
if (!tap.results && tap.timeout)
tap.timeout(extra)
else {
Expand All @@ -125,6 +129,7 @@ onExit(function (code, signal) {
var yaml = require('js-yaml')
console.error(objToYaml(extra))
}
process.exit(1)
didTimeoutKill = true
process.kill(process.pid, 'SIGTERM')
}
})
2 changes: 1 addition & 1 deletion test/test/child-sigterm-after-end--bail--buffer.tap
Expand Up @@ -8,7 +8,7 @@ possible timeout: SIGTERM received after tap end
{"handles":[{"type":"Timer"}]}
...

# child end code=1 signal=null
# child end code=null signal="SIGTERM"
ok 1 - should not be equal
1..1

2 changes: 1 addition & 1 deletion test/test/child-sigterm-after-end--bail.tap
Expand Up @@ -8,7 +8,7 @@ possible timeout: SIGTERM received after tap end
{"handles":[{"type":"Timer"}]}
...

# child end code=1 signal=null
# child end code=null signal="SIGTERM"
ok 1 - should not be equal
1..1

2 changes: 1 addition & 1 deletion test/test/child-sigterm-after-end--buffer.tap
Expand Up @@ -8,7 +8,7 @@ possible timeout: SIGTERM received after tap end
{"handles":[{"type":"Timer"}]}
...

# child end code=1 signal=null
# child end code=null signal="SIGTERM"
ok 1 - should not be equal
1..1

2 changes: 1 addition & 1 deletion test/test/child-sigterm-after-end.tap
Expand Up @@ -8,7 +8,7 @@ possible timeout: SIGTERM received after tap end
{"handles":[{"type":"Timer"}]}
...

# child end code=1 signal=null
# child end code=null signal="SIGTERM"
ok 1 - should not be equal
1..1

0 comments on commit 9bb81dc

Please sign in to comment.