diff --git a/lib/root.js b/lib/root.js index 2e16a811e..ba78faf23 100644 --- a/lib/root.js +++ b/lib/root.js @@ -64,20 +64,25 @@ onExit(function (code, signal) { h !== process.stderr }) var requests = process._getActiveRequests() - var msg = 'received SIGTERM with pending event queue activity' // Ignore this because it's really hard to test cover in a way // that isn't inconsistent and unpredictable. /* istanbul ignore next */ - tap.fail(msg, { - requests: requests.map(function (r) { + var extra = { + at: null, + signal: signal + } + if (requests.length) { + extra.requests = requests.map(function (r) { var ret = { type: r.constructor.name } if (r.context) { ret.context = r.context } return ret - }), - handles: handles.map(function (h) { + }) + } + if (handles.length) { + extra.handles = handles.map(function (h) { var ret = { type: h.constructor.name } if (h.msecs) { ret.msecs = h.msecs @@ -92,9 +97,8 @@ onExit(function (code, signal) { ret.connectionKey = h._connectionKey } return ret - }), - at: null - }) + }) + } - tap.end() + tap._onTimeout(extra) }) diff --git a/lib/test.js b/lib/test.js index 289b4bdd1..94eef8264 100644 --- a/lib/test.js +++ b/lib/test.js @@ -150,7 +150,8 @@ Test.prototype.setTimeout = function (n) { }, n) } -Test.prototype._onTimeout = function () { +Test.prototype._onTimeout = function (extra) { + // anything that was pending will have to wait. var s = this while (s._currentChild && (s._currentChild instanceof Test)) { s._queue = [] @@ -158,12 +159,15 @@ Test.prototype._onTimeout = function () { s = s._currentChild } - // anything that was pending will have to wait. - s.fail('timeout!', { - expired: this._name, - timeout: this._timeout, - at: this._calledAt - }) + extra = extra || {} + if (this._parent) { + extra.expired = this._name + } + if (this._timeout) { + extra.timeout = this._timeout + } + extra.at = this._calledAt + s.fail('timeout!', extra) s.end(IMPLICIT) this.endAll() diff --git a/test/runner.js b/test/runner.js index a43a25502..83ddc8f78 100644 --- a/test/runner.js +++ b/test/runner.js @@ -491,7 +491,7 @@ t.test('-t or --timeout to set timeout', function (t) { t.equal(signal, null) t.match( out, - /received SIGTERM with pending event queue activity/, + /signal: SIGTERM/, { skip: skip } ) t.end() diff --git a/test/test/pending-handles-bail.tap b/test/test/pending-handles-bail.tap index 540652c61..bbe12948f 100644 --- a/test/test/pending-handles-bail.tap +++ b/test/test/pending-handles-bail.tap @@ -1,10 +1,10 @@ TAP version 13 # Subtest: ___/.*/~~~pending-handles.js child ok 1 - this is ok - not ok 2 - received SIGTERM with pending event queue activity + not ok 2 - timeout! --- - {"handles":[{"msecs":100000,"type":"Timer"}],"requests":[]} + {"handles":[{"msecs":100000,"type":"Timer"}],"signal":"SIGTERM"} ... - Bail out! # received SIGTERM with pending event queue activity -Bail out! # received SIGTERM with pending event queue activity + Bail out! # timeout! +Bail out! # timeout! diff --git a/test/test/pending-handles.tap b/test/test/pending-handles.tap index 190d29142..cb101127f 100644 --- a/test/test/pending-handles.tap +++ b/test/test/pending-handles.tap @@ -1,9 +1,9 @@ TAP version 13 # Subtest: ___/.*/~~~pending-handles.js child ok 1 - this is ok - not ok 2 - received SIGTERM with pending event queue activity + not ok 2 - timeout! --- - {"handles":[{"msecs":100000,"type":"Timer"}],"requests":[]} + {"handles":[{"msecs":100000,"type":"Timer"}],"signal":"SIGTERM"} ... 1..2 # failed 1 of 2 tests diff --git a/test/test/timeout-via-runner-bail.tap b/test/test/timeout-via-runner-bail.tap new file mode 100644 index 000000000..b2c7102cc --- /dev/null +++ b/test/test/timeout-via-runner-bail.tap @@ -0,0 +1,12 @@ +TAP version 13 + # Subtest: child + # Subtest: child test + 1..2 + ok 1 - this is fine + not ok 2 - timeout! + --- + {"handles":[{"msecs":20000,"type":"Timer"}],"signal":"SIGTERM"} + ... + Bail out! # timeout! +Bail out! # timeout! + diff --git a/test/test/timeout-via-runner.js b/test/test/timeout-via-runner.js new file mode 100644 index 000000000..f46a3c192 --- /dev/null +++ b/test/test/timeout-via-runner.js @@ -0,0 +1,13 @@ +var t = require('../..') + +if (process.argv[2] === 'child') { + t.test('child test', function (t) { + t.plan(2) + t.pass('this is fine') + setTimeout(function (res) { + t.pass('request complete') + }, 20000) + }) +} else { + t.spawn(process.execPath, [__filename, 'child'], {}, 'child', { timeout: 1000 }) +} diff --git a/test/test/timeout-via-runner.tap b/test/test/timeout-via-runner.tap new file mode 100644 index 000000000..074c8c883 --- /dev/null +++ b/test/test/timeout-via-runner.tap @@ -0,0 +1,27 @@ +TAP version 13 + # Subtest: child + # Subtest: child test + 1..2 + ok 1 - this is fine + not ok 2 - timeout! + --- + {"handles":[{"msecs":20000,"type":"Timer"}],"signal":"SIGTERM"} + ... + # failed 1 of 2 tests + not ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~ + --- + {"at":{"column":5,"file":"test/test/timeout-via-runner.js","line":4},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('child test', function (t) {\n"} + ... + + 1..1 + # failed 1 of 1 tests + ___/# time=[0-9.]+(ms)?/~~~ +not ok 1 - child ___/# time=[0-9.]+(ms)?/~~~ + --- + {"arguments":["___/.*/~~~timeout-via-runner.js","child"],"at":{"column":5,"file":"test/test/timeout-via-runner.js","line":12},"command":"___/.*(node|iojs)(.exe)?/~~~","failure":"timeout","results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"signal":"SIGTERM","source":"t.spawn(process.execPath, [__filename, 'child'], {}, 'child', { timeout: 1000 })\n","timeout":1000} + ... + +1..1 +# failed 1 of 1 tests +___/# time=[0-9.]+(ms)?/~~~ + diff --git a/test/timeout.js b/test/timeout.js index d8d589e62..84a8012d3 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -40,7 +40,7 @@ tap.test('t.setTimeout()', function (t) { tt.setTimeout('not a number') }, {}, { message: 'setTimeout: number > 0 required' }) - var tt = new Test({ timeout: 1000 }) + var tt = new Test({ timeout: 1000, bail: false }) tt.setTimeout(2000) tt.setTimeout(Infinity) t.notOk(tt._timeout) @@ -51,15 +51,14 @@ tap.test('t.setTimeout()', function (t) { ' ok 1 - this is fine\n' + ' not ok 2 - timeout!\n' + ' ---\n' + - '( expired: some name\n|' + - ' timeout: 1\n){2}' + + ' timeout: 1\n' + ' \\.\\.\\.\n' + ' 1..2\n' + ' # failed 1 of 2 tests\n' + 'not ok 1 - child test # time=') - tt = new Test({ name: 'some name' }) - tt.test('child test', function (tt) { + tt = new Test({ name: 'some name', bail: false }) + tt.test('child test', { bail: false }, function (tt) { tt.pass('this is fine') }) tt.setTimeout(1)