Permalink
Browse files

failing test from reconnecting to the hub and a remote host at the sa…

…me time
  • Loading branch information...
1 parent 2cdaa60 commit 51eba6d897ba3084c4820cbfbf900562abb76695 @substack committed Sep 8, 2012
Showing with 89 additions and 0 deletions.
  1. +75 −0 test/recon.js
  2. +14 −0 test/recon/server.js
View
@@ -0,0 +1,75 @@
+var test = require('tap').test;
+var spawn = require('child_process').spawn;
+var airport = require('airport');
+var seaport = require('seaport');
+var port = Math.floor(Math.random() * 5e4 + 1e4);
+
+function createHub () {
+ return spawn(process.execPath, [
+ __dirname + '/../node_modules/.bin/seaport',
+ port
+ ]);
+}
+
+function createServer () {
+ return spawn(process.execPath, [
+ __dirname + '/recon/server.js',
+ port
+ ]);
+}
+
+function runProc (fn) {
+ var ps = fn();
+ setTimeout(function () {
+ ps.kill();
+ setTimeout(function () {
+ if (ref.stopped) return;
+ ref.stop = runProc(fn).stop;
+ }, Math.random() * 500);
+ }, 400 + Math.random() * 500);
+
+ var ref = {};
+ ref.stop = function () {
+ ref.stopped = true;
+ ps.kill();
+ };
+ return ref;
+}
+
+test('reconnection race', function (t) {
+ t.plan(2);
+
+ var air = airport('localhost', port);
+ var up = air.connect('q');
+ var results = [];
+
+ var iv = setInterval(function () {
+ up(function (remote) {
+ remote.beep(function (s) {
+ results.push(s);
+ console.log(s);
+ });
+ });
+ }, 100);
+
+ var mark;
+ setTimeout(function () {
+ t.ok(results.length > 10 * 2, 'enough initial events');
+ console.log('--- mark ---');
+ mark = results.length;
+ }, 10 * 1000);
+
+ setTimeout(function () {
+ t.ok(results.length > mark, 'events have come through');
+ console.log('--- stop ---');
+ }, 20 * 1000);
+
+ var server = runProc(createServer);
+ var hub = runProc(createHub);
+ t.on('end', function () {
+ server.stop();
+ hub.stop();
+ if (up.close) up.close();
+ clearInterval(iv);
+ });
+});
View
@@ -0,0 +1,14 @@
+var airport = require('airport');
+var air = airport('localhost', Number(process.argv[2]));
+var ix = 0;
+
+return air(function () {
+ this.beep = function (cb) {
+ if (typeof cb === 'function') {
+ var xs = 'boop'.split('');
+ xs[ix] = xs[ix].toUpperCase();
+ ix = (ix + 1) % xs.length;
+ cb(xs.join(''));
+ }
+ };
+}).listen('q');

0 comments on commit 51eba6d

Please sign in to comment.