test: fix race in parallel/test-vm-debug-context
authorBen Noordhuis <info@bnoordhuis.nl>
Sun, 29 Mar 2015 18:09:22 +0000 (20:09 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Sun, 29 Mar 2015 22:29:28 +0000 (00:29 +0200)
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: https://github.com/iojs/io.js/issues/1291
PR-URL: https://github.com/iojs/io.js/pull/1294
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
test/parallel/test-vm-debug-context.js

index da2a447..2c69194 100644 (file)
@@ -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']);