child_process: fix test implementation for options.detached
authorCharlie McConnell <charlie@charlieistheman.com>
Fri, 1 Jun 2012 04:23:05 +0000 (21:23 -0700)
committerisaacs <i@izs.me>
Mon, 11 Jun 2012 17:27:51 +0000 (10:27 -0700)
test/fixtures/parent-process-nonpersistent.js [new file with mode: 0644]
test/simple/test-child-process-detached.js

diff --git a/test/fixtures/parent-process-nonpersistent.js b/test/fixtures/parent-process-nonpersistent.js
new file mode 100644 (file)
index 0000000..a71d1a3
--- /dev/null
@@ -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();
index 4683414..10ce5d1 100644 (file)
@@ -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);
+  });
 });