-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for a unref'ed timer leak
PR-URL: #1330 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var assert = require('assert'); | ||
|
||
var called = 0; | ||
var closed = 0; | ||
|
||
var timeout = setTimeout(function() { | ||
called++; | ||
}, 10); | ||
timeout.unref(); | ||
|
||
// Wrap `close` method to check if the handle was closed | ||
var close = timeout._handle.close; | ||
timeout._handle.close = function() { | ||
closed++; | ||
return close.apply(this, arguments); | ||
}; | ||
|
||
// Just to keep process alive and let previous timer's handle die | ||
setTimeout(function() { | ||
}, 50); | ||
|
||
process.on('exit', function() { | ||
assert.equal(called, 1); | ||
assert.equal(closed, 1); | ||
}); |