Skip to content

Commit

Permalink
fix: kill child process when hyperquest fail fix #186
Browse files Browse the repository at this point in the history
  • Loading branch information
ccarruitero committed May 15, 2020
1 parent a3d3237 commit a014b3a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions exercises/hello_hapi/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ exercise.addProcessor(function (mode, callback) {
// compare stdout of solution and submission
exercise = comparestdout(exercise);

function killChild (exercise) {
[ exercise.submissionChild, exercise.solutionChild ].forEach(function (child) {
if (child && typeof child.kill == 'function') child.kill()
})
}

// delayed for 2000ms to wait for servers to start so we can start
// playing with them
function query (mode) {
Expand All @@ -60,6 +66,7 @@ function query (mode) {
function error (err) {
const msg = exercise.__('fail.cannot_connect', port, err.code);
exercise.emit('fail', msg);
killChild(exercise);
}

hyperquest.get(`http://localhost:${port}/`)
Expand Down

0 comments on commit a014b3a

Please sign in to comment.