summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie McConnell <charlie@charlieistheman.com>2012-05-31 21:23:05 -0700
committerisaacs <i@izs.me>2012-06-11 10:27:51 -0700
commit2eb181d28c71e20307166c06317cdd03d102854c (patch)
tree1f17d24ec7d602a677ac25f1067351e215cc861a
parent25e8ea17e1f03cd40cc5a6c9c1987bae58313ff5 (diff)
downloadnode-new-2eb181d28c71e20307166c06317cdd03d102854c.tar.gz
child_process: fix test implementation for options.detached
-rw-r--r--test/fixtures/parent-process-nonpersistent.js13
-rw-r--r--test/simple/test-child-process-detached.js19
2 files changed, 26 insertions, 6 deletions
diff --git a/test/fixtures/parent-process-nonpersistent.js b/test/fixtures/parent-process-nonpersistent.js
new file mode 100644
index 0000000000..a71d1a3882
--- /dev/null
+++ b/test/fixtures/parent-process-nonpersistent.js
@@ -0,0 +1,13 @@
+
+var spawn = require('child_process').spawn,
+ path = require('path'),
+ childPath = path.join(__dirname, 'child-process-persistent.js');
+
+var child = spawn(process.execPath, [ childPath ], {
+ detached: true,
+ stdio: 'ignore'
+});
+
+console.log(child.pid);
+
+child.unref();
diff --git a/test/simple/test-child-process-detached.js b/test/simple/test-child-process-detached.js
index 4683414a0f..10ce5d1527 100644
--- a/test/simple/test-child-process-detached.js
+++ b/test/simple/test-child-process-detached.js
@@ -24,15 +24,22 @@ var assert = require('assert');
var path = require('path');
var spawn = require('child_process').spawn;
-var childPath = path.join(__dirname, '..', 'fixtures', 'child-process-persistent.js');
+var childPath = path.join(__dirname, '..', 'fixtures', 'parent-process-nonpersistent.js');
+var persistentPid = -1;
-var child = spawn(process.execPath, [ childPath ], {
- detached: true,
- stdio: 'ignore'
+var child = spawn(process.execPath, [ childPath ]);
+
+child.stdout.on('data', function (data) {
+ persistentPid = parseInt(data, 10);
});
process.on('exit', function () {
- process.kill(child.pid);
- assert.throws(process.kill(child.pid), Error);
+ assert(persistentPid !== -1);
+ assert.throws(function () {
+ process.kill(child.pid);
+ });
+ assert.doesNotThrow(function () {
+ process.kill(persistentPid);
+ });
});