Skip to content

Commit fbc83b0

Browse files
committed
Handing timeout SIGTERMs after explicit root test end
Previously, it'd just throw a 'test after end' exception because the onTimeout method emits a fail(). This prints something at least a little useful to stderr before exiting in failure.
1 parent 4f50bf0 commit fbc83b0

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

lib/root.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,20 @@ onExit(function (code, signal) {
133133
})
134134
}
135135

136-
tap._onTimeout(extra)
136+
if (!tap._ended) {
137+
tap._onTimeout(extra)
138+
} else {
139+
console.error('possible timeout: SIGTERM received after tap end')
140+
if (extra.handles || extra.requests) {
141+
delete extra.signal
142+
if (!extra.at) {
143+
delete extra.at
144+
}
145+
var yaml = require('js-yaml')
146+
console.error(' ---\n ' +
147+
yaml.safeDump(extra).split('\n').join('\n ').trim() +
148+
'\n ...\n')
149+
}
150+
process.exit(1)
151+
}
137152
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TAP version 13
2+
# child start
3+
TAP version 13
4+
ok 1 - this is fine
5+
1..1
6+
___/# time=[0-9.]+(ms)?/~~~
7+
possible timeout: SIGTERM received after tap end
8+
---
9+
{"handles":[{"type":"Timer"}]}
10+
...
11+
12+
# child end code=1 signal=null
13+
ok 1 - should not be equal
14+
1..1
15+
___/# time=[0-9.]+(ms)?/~~~
16+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var t = require('../..')
2+
if (process.argv[2] === 'child') {
3+
setInterval(function () {}, 10000)
4+
t.pass('this is fine')
5+
t.end()
6+
// use ipc so that we're not waiting longer than necessary
7+
process.send({ do: 'it' })
8+
} else {
9+
t.comment('child start')
10+
var spawn = require('child_process').spawn
11+
var child = spawn(process.execPath, [__filename, 'child'], {
12+
stdio: [ 0, 1, 1, 'ipc']
13+
})
14+
child.on('message', function () {
15+
child.kill('SIGTERM')
16+
})
17+
child.on('exit', function (code, signal) {
18+
t.comment('child end code=%j signal=%j', code, signal)
19+
t.notEqual(code, 0)
20+
t.end()
21+
})
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TAP version 13
2+
# child start
3+
TAP version 13
4+
ok 1 - this is fine
5+
1..1
6+
___/# time=[0-9.]+(ms)?/~~~
7+
possible timeout: SIGTERM received after tap end
8+
---
9+
{"handles":[{"type":"Timer"}]}
10+
...
11+
12+
# child end code=1 signal=null
13+
ok 1 - should not be equal
14+
1..1
15+
___/# time=[0-9.]+(ms)?/~~~
16+

0 commit comments

Comments
 (0)