-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test and docs for detached fork process
This tests child process fork component in detached mode by spawning a parent process that creates a child process. We kill the parent process and check if the child is still running. Fixes: #17592 PR-URL: #24524 Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
1 parent
8041380
commit f051737
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fork = require('child_process').fork; | ||
const path = require('path'); | ||
|
||
const child = fork( | ||
path.join(__dirname, 'child-process-persistent.js'), | ||
[], | ||
{ detached: true, stdio: 'ignore' } | ||
); | ||
|
||
console.log(child.pid); | ||
|
||
child.unref(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const fork = require('child_process').fork; | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const nonPersistentNode = fork( | ||
fixtures.path('parent-process-nonpersistent-fork.js'), | ||
[], | ||
{ silent: true }); | ||
|
||
let childId = -1; | ||
|
||
nonPersistentNode.stdout.on('data', (data) => { | ||
childId = parseInt(data, 10); | ||
nonPersistentNode.kill(); | ||
}); | ||
|
||
process.on('exit', () => { | ||
assert.notStrictEqual(childId, -1); | ||
// Killing the child process should not throw an error | ||
process.kill(childId); | ||
}); |