test: fix test-child-process-stdout-flush-exit
authorSantiago Gimeno <santiago.gimeno@gmail.com>
Tue, 2 Jun 2015 08:39:55 +0000 (10:39 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Tue, 2 Jun 2015 17:25:22 +0000 (19:25 +0200)
Make sure all the stdout data is available before
performing the assertions.

Fixes: https://github.com/nodejs/io.js/issues/944
PR-URL: https://github.com/nodejs/io.js/pull/1868
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
test/parallel/test-child-process-stdout-flush-exit.js

index 0d4e353..577a33a 100644 (file)
@@ -18,8 +18,7 @@ if (process.argv[2] === 'child') {
   // spawn self as child
   var child = spawn(process.argv[0], [process.argv[1], 'child']);
 
-  var gotHello = false;
-  var gotBye = false;
+  var stdout = '';
 
   child.stderr.setEncoding('utf8');
   child.stderr.on('data', function(data) {
@@ -30,17 +29,11 @@ if (process.argv[2] === 'child') {
   // check if we receive both 'hello' at start and 'goodbye' at end
   child.stdout.setEncoding('utf8');
   child.stdout.on('data', function(data) {
-    if (data.slice(0, 6) == 'hello\n') {
-      gotHello = true;
-    } else if (data.slice(data.length - 8) == 'goodbye\n') {
-      gotBye = true;
-    } else {
-      gotBye = false;
-    }
+    stdout += data;
   });
 
-  child.on('close', function(data) {
-    assert(gotHello);
-    assert(gotBye);
-  });
+  child.on('close', common.mustCall(function() {
+    assert.equal(stdout.slice(0, 6), 'hello\n');
+    assert.equal(stdout.slice(stdout.length - 8), 'goodbye\n');
+  }));
 }