mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/14616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>v6
8 changed files with 68 additions and 131 deletions
@ -1,27 +1,14 @@ |
|||||
'use strict'; |
'use strict'; |
||||
require('../common'); |
const common = require('../common'); |
||||
const assert = require('assert'); |
|
||||
|
|
||||
let called = 0; |
const timeout = setTimeout(common.mustCall(), 10); |
||||
let closed = 0; |
|
||||
|
|
||||
const timeout = setTimeout(function() { |
|
||||
called++; |
|
||||
}, 10); |
|
||||
timeout.unref(); |
timeout.unref(); |
||||
|
|
||||
// Wrap `close` method to check if the handle was closed
|
// Wrap `close` method to check if the handle was closed
|
||||
const close = timeout._handle.close; |
const close = timeout._handle.close; |
||||
timeout._handle.close = function() { |
timeout._handle.close = common.mustCall(function() { |
||||
closed++; |
|
||||
return close.apply(this, arguments); |
return close.apply(this, arguments); |
||||
}; |
}); |
||||
|
|
||||
// Just to keep process alive and let previous timer's handle die
|
// Just to keep process alive and let previous timer's handle die
|
||||
setTimeout(function() { |
setTimeout(() => {}, 50); |
||||
}, 50); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
assert.strictEqual(called, 1); |
|
||||
assert.strictEqual(closed, 1); |
|
||||
}); |
|
||||
|
@ -1,20 +1,7 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
require('../common'); |
const common = require('../common'); |
||||
const assert = require('assert'); |
|
||||
|
|
||||
let once = 0; |
process.on('beforeExit', common.mustCall(() => { |
||||
|
setTimeout(common.mustNotCall(), 1).unref(); |
||||
process.on('beforeExit', () => { |
})); |
||||
if (once > 1) |
|
||||
throw new RangeError('beforeExit should only have been called once!'); |
|
||||
|
|
||||
setTimeout(() => {}, 1).unref(); |
|
||||
once++; |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', (code) => { |
|
||||
if (code !== 0) return; |
|
||||
|
|
||||
assert.strictEqual(once, 1); |
|
||||
}); |
|
||||
|
Loading…
Reference in new issue