From 27027fcb0b0fa2ab41b1308e4620c1b2e7894cd8 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Wed, 16 Nov 2011 20:35:03 +0100 Subject: [PATCH] add a (working) gc test :) Note: this needs https://github.com/isaacs/tap-runner/pull/6. With older tap-runner versions, it complains about missing `gc()` function. --- test/gc.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/gc.js diff --git a/test/gc.js b/test/gc.js new file mode 100644 index 0000000..88bd84d --- /dev/null +++ b/test/gc.js @@ -0,0 +1,56 @@ +#! node --expose-gc +var dnode = require('../'); +var test = require('tap').test; +var weak = require('weak'); + +test('gc', function (t) { + t.plan(2); + var port = Math.floor(Math.random() * 40000 + 10000); + + var gcLoopIterations = 0; + var server_ok = false, client_ok = false; + + function forced_gc_loop() { + gc(); + if (++gcLoopIterations < 50) { + setTimeout(forced_gc_loop, 100); + } else { + if (!server_ok || !client_ok) t.end(); + setTimeout(function() { + process.exit(); + }, 1000); + } + } + forced_gc_loop(); + + function onSuccess() { + t.end(); + setTimeout(process.exit, 500); + } + + var server = dnode({ + callMeBack : function (fn) { + fn('calling back!'); + weak(fn, function() { + t.ok(true); + server_ok = true; + if (client_ok) onSuccess(); + }); + } + }).listen(port); + + server.on('ready', function () { + dnode.connect(port, function (remote, conn) { + function weakCb() { + t.ok(true); + client_ok = true; + if (server_ok) onSuccess(); + } + (function() { + var cb = function(){}; + remote.callMeBack(cb); + weak(cb, weakCb); + })(); + }); + }); +});