test: add test for a unref'ed timer leak
authorFedor Indutny <fedor@indutny.com>
Fri, 3 Apr 2015 22:08:20 +0000 (01:08 +0300)
committerFedor Indutny <fedor@indutny.com>
Fri, 3 Apr 2015 23:31:50 +0000 (02:31 +0300)
PR-URL: https://github.com/iojs/io.js/pull/1330
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
test/parallel/test-timers-unref-leak.js [new file with mode: 0644]

diff --git a/test/parallel/test-timers-unref-leak.js b/test/parallel/test-timers-unref-leak.js
new file mode 100644 (file)
index 0000000..c8f958a
--- /dev/null
@@ -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);
+});