Skip to content

Commit 6f72d87

Browse files
committed
test: add test for a unref'ed timer leak
PR-URL: #1330 Reviewed-by: Trevor Norris <[email protected]>
1 parent d22b2a9 commit 6f72d87

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var assert = require('assert');
2+
3+
var called = 0;
4+
var closed = 0;
5+
6+
var timeout = setTimeout(function() {
7+
called++;
8+
}, 10);
9+
timeout.unref();
10+
11+
// Wrap `close` method to check if the handle was closed
12+
var close = timeout._handle.close;
13+
timeout._handle.close = function() {
14+
closed++;
15+
return close.apply(this, arguments);
16+
};
17+
18+
// Just to keep process alive and let previous timer's handle die
19+
setTimeout(function() {
20+
}, 50);
21+
22+
process.on('exit', function() {
23+
assert.equal(called, 1);
24+
assert.equal(closed, 1);
25+
});

0 commit comments

Comments
 (0)