test: fix test-debug-port-from-cmdline
authorJoão Reis <reis@janeasystems.com>
Wed, 15 Jul 2015 12:19:56 +0000 (13:19 +0100)
committercjihrig <cjihrig@gmail.com>
Thu, 16 Jul 2015 01:52:16 +0000 (21:52 -0400)
This test was failing because the spawned process was terminated before
anything could be done, by calling child.stdin.end. With this change,
the child's stdin is no longer closed. When the stdin is not a tty,
io.js waits for the whole input before starting, so the child must be
run with --interactive to process the command sent by the parent. The
child is killed explicitly by the parent before it exits.

This test was failing silently because the asserts were not called if
nothing was received from the child. This fix moves assertOutputLines to
always run on exit.

Fixes: https://github.com/nodejs/io.js/issues/2177
Refs: https://github.com/nodejs/io.js/issues/2094
PR-URL: https://github.com/nodejs/io.js/pull/2186
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Alexis Campailla <alexis@janeasystems.com>
test/parallel/test-debug-port-from-cmdline.js

index deb7ae241a55fde1b37f8bf32978888d6c99fec1..71ed71bd63af65d7db706cfc9e48e9323d79354f 100644 (file)
@@ -4,11 +4,11 @@ var assert = require('assert');
 var spawn = require('child_process').spawn;
 
 var debugPort = common.PORT;
-var args = ['--debug-port=' + debugPort];
+var args = ['--interactive', '--debug-port=' + debugPort];
 var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] };
 var child = spawn(process.execPath, args, childOptions);
 
-child.stdin.end("process.send({ msg: 'childready' });");
+child.stdin.write("process.send({ msg: 'childready' });\n");
 
 child.stderr.on('data', function(data) {
   var lines = data.toString().replace(/\r/g, '').trim().split('\n');
@@ -23,6 +23,7 @@ child.on('message', function onChildMsg(message) {
 
 process.on('exit', function() {
   child.kill();
+  assertOutputLines();
 });
 
 var outputLines = [];
@@ -31,7 +32,6 @@ function processStderrLine(line) {
   outputLines.push(line);
 
   if (/Debugger listening/.test(line)) {
-    assertOutputLines();
     process.exit();
   }
 }