Skip to content

Commit

Permalink
test: fix test-child-process-stdout-flush-exit
Browse files Browse the repository at this point in the history
Make sure all the stdout data is available before
performing the assertions.

Fixes: #944
PR-URL: #1868
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
santigimeno authored and bnoordhuis committed Jun 2, 2015
1 parent d20f018 commit b926718
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions test/parallel/test-child-process-stdout-flush-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
}));
}

0 comments on commit b926718

Please sign in to comment.