Permalink
Browse files

updated the hub down server down test, still fails

  • Loading branch information...
1 parent 8ab5614 commit acb4825ba879e5419b5410f580f143f1b82fc4a0 @substack committed Sep 1, 2013
Showing with 38 additions and 33 deletions.
  1. +2 −1 package.json
  2. +33 −31 test/hub_down_server_down.js
  3. +3 −1 test/hub_down_server_down/hub.js
View
@@ -27,7 +27,8 @@
"seaport" : "~1.5.3"
},
"devDependencies" : {
- "tap" : "~0.3.0"
+ "tap" : "~0.4.0",
+ "split" : "~0.2.10"
},
"engines" : {
"node" : ">=0.6.0"
@@ -1,9 +1,10 @@
var test = require('tap').test;
var seaport = require('seaport');
var spawn = require('child_process').spawn;
+var split = require('split');
test('hub goes down, server goes down', function (t) {
- t.plan(2);
+ t.plan(3);
var port = Math.floor(Math.random() * 5e4 + 1e4);
@@ -20,36 +21,37 @@ test('hub goes down, server goes down', function (t) {
hub : sh('hub.js'),
};
- var data = '';
- ps.client.stdout.on('data', function (buf) { data += buf });
-ps.client.stderr.pipe(process.stderr, { end : false });
- function checkOutput () {
-console.dir(data);
- t.same(data.split(/\r?\n/).slice(-3)[0], 'down');
- t.same(data.split(/\r?\n/).slice(-2)[0], 'up');
- }
-
- setTimeout(function () {
- ps.hub.kill();
- ps.server.kill();
- }, 1500);
-
- setTimeout(function () {
- ps.hub = sh('hub.js');
- }, 2.5 * 1000);
-
- setTimeout(function () {
- ps.hub.kill();
- ps.hub = sh('hub.js');
- }, 4 * 1000);
-
- setTimeout(function () {
- ps.server = sh('server.js');
- }, 4.5 * 1000);
-
- setTimeout(function () {
- checkOutput();
- }, 8 * 1000);
+ var lines = [];
+ ps.client.stdout.pipe(split()).on('data', function (buf) {
+ var line = buf.toString('utf8');
+ lines.push(line);
+
+ if (lines.length === 1) {
+ t.equal(line, 'up');
+ ps.hub.kill();
+ ps.server.kill();
+ }
+ else if (lines.length === 2) {
+ t.equal(line, 'down');
+ ps.hub = sh('hub.js');
+ ps.hub.stdout.once('data', function () {
+ setTimeout(function () {
+ ps.hub.kill();
+ }, 1000);
+
+ setTimeout(function () {
+ ps.hub = sh('hub.js');
+ }, 1500);
+
+ setTimeout(function () {
+ ps.server = sh('server.js');
+ }, 2000);
+ });
+ }
+ else if (lines.length === 3) {
+ t.equal(line, 'up');
+ }
+ });
t.on('end', function () {
ps.hub.kill();
@@ -1,4 +1,6 @@
var seaport = require('seaport');
var port = process.argv[2];
var server = seaport.createServer();
-server.listen(parseInt(port, 10));
+server.listen(parseInt(port, 10), function () {
+ console.log('ready');
+});

0 comments on commit acb4825

Please sign in to comment.