Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a (working) gc test :)

Note: this needs isaacs/tap-runner#6.
With older tap-runner versions, it complains about missing
`gc()` function.
  • Loading branch information...
commit 27027fcb0b0fa2ab41b1308e4620c1b2e7894cd8 1 parent fd13cec
@thejh authored
Showing with 56 additions and 0 deletions.
  1. +56 −0 test/gc.js
View
56 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);
+ })();
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.