Skip to content
Permalink
Browse files
feat: kill any child processes of server (#3)
* chore(test): Added test case where child process is not closed

* minor(stop): Also kill child processes of the server

* fix(deps): remove unused eslint plugins
  • Loading branch information
dallonf authored and bahmutov committed Mar 14, 2018
1 parent 591e4cd commit ce26532dec407a4dce6a310d9d633449f3ebb52d
Showing with 31 additions and 9 deletions.
  1. +9 −7 package.json
  2. +13 −2 src/index.js
  3. +9 −0 test/server-as-child.js
@@ -72,9 +72,11 @@
"unused-deps": "dependency-check --unused --no-dev .",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"start": "node test/server.js",
"start-with-child": "node test/server-as-child.js",
"test2": "curl http://127.0.0.1:9000",
"demo": "node bin/start.js http://127.0.0.1:9000",
"demo2": "node bin/start.js start http://127.0.0.1:9000 test2"
"demo2": "node bin/start.js start http://127.0.0.1:9000 test2",
"demo3": "node bin/start.js start-with-child http://127.0.0.1:9000 test"
},
"release": {
"analyzeCommits": "simple-commit-message",
@@ -85,7 +87,7 @@
}
},
"devDependencies": {
"ban-sensitive-files": "1.9.0",
"ban-sensitive-files": "1.9.2",
"dependency-check": "2.9.1",
"deps-ok": "1.2.1",
"dont-crack": "1.2.1",
@@ -101,12 +103,12 @@
"standard": "10.0.3"
},
"dependencies": {
"bluebird": "3.5.1",
"check-more-types": "2.24.0",
"lazy-ass": "1.6.0",
"debug": "3.1.0",
"execa": "0.8.0",
"wait-on": "2.0.2",
"bluebird": "3.5.1",
"debug": "3.1.0"
"lazy-ass": "1.6.0",
"ps-tree": "1.1.0",
"wait-on": "2.0.2"
}
}

@@ -5,6 +5,7 @@ const is = require('check-more-types')
const execa = require('execa')
const waitOn = require('wait-on')
const Promise = require('bluebird')
const psTree = require('ps-tree')
const debug = require('debug')('start-server-and-test')

function startAndTest ({ start, url, test }) {
@@ -17,10 +18,20 @@ function startAndTest ({ start, url, test }) {
let serverStopped

function stopServer () {
debug('getting child processes')
if (!serverStopped) {
debug('stopping server')
server.kill()
serverStopped = true
return Promise.fromNode(cb => psTree(server.pid, cb))
.then(children => {
debug('stopping child processes')
children.forEach(child => {
process.kill(child.PID)
})
})
.then(() => {
debug('stopping server')
server.kill()
})
}
}

@@ -0,0 +1,9 @@
const childProcess = require('child_process');

console.log('Starting server as child process');
const result = childProcess.spawnSync(
'node',
[].concat(require.resolve('./server')).concat(process.argv),
{ stdio: 'inherit' }
);
console.log('Done');

0 comments on commit ce26532

Please sign in to comment.