Skip to content

Commit

Permalink
test: fix race in parallel/test-vm-debug-context
Browse files Browse the repository at this point in the history
Fix a race condition in parallel/test-vm-debug-context where the 'exit'
event for the child process is emitted before the first and only 'data'
event for the child process's stderr stream.

I considered deferring the 'exit' event in lib/child_process.js until
all stdio streams have been closed but I realized that's not going to
work when the child process spins off grandchildren that keep the stdio
file descriptors alive.

Fixes: #1291
PR-URL: #1294
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
  • Loading branch information
bnoordhuis committed Mar 29, 2015
1 parent ea37ac0 commit 8d1c87e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/parallel/test-vm-debug-context.js
Expand Up @@ -58,11 +58,13 @@ var proc = spawn(process.execPath, [script]);
var data = [];
proc.stdout.on('data', assert.fail);
proc.stderr.on('data', data.push.bind(data));
proc.stderr.once('end', common.mustCall(function() {
var haystack = Buffer.concat(data).toString('utf8');
assert(/SyntaxError: Unexpected token \*/.test(haystack));
}));
proc.once('exit', common.mustCall(function(exitCode, signalCode) {
assert.equal(exitCode, 1);
assert.equal(signalCode, null);
var haystack = Buffer.concat(data).toString('utf8');
assert(/SyntaxError: Unexpected token \*/.test(haystack));
}));

var proc = spawn(process.execPath, [script, 'handle-fatal-exception']);
Expand Down

0 comments on commit 8d1c87e

Please sign in to comment.