exec(command, (error, stdout) => { if (error) { if (error.signal == 'SIGTERM') { resolve('Process was killed'); } else { reject(error); } } else { resolve(stdout.trim()); } });
exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout) => { if (error) { // Special case for robocopy, which will return non-zero error codes // when sucessful. Doc is very imprecise but <= 7 seems more or less // fine and >= 8 seems more errorish. https://ss64.com/nt/robocopy-exit.html if (command.indexOf('robocopy') === 0 && error.code <= 7) { resolve(stdout.trim()); return; } if (error.signal == 'SIGTERM') { resolve('Process was killed'); } else { const newError = new Error(`Code: ${error.code}: ${error.message}: ${stdout.trim()}`); reject(newError); } } else { resolve(stdout.trim()); } });
it('returns 503 once signal received', (done) => { let responseAssertionsComplete = false // We're only truly finished when the response has been analyzed and the forked http process has exited, // freeing up port 8000 for future tests execFile('node', ['lib/standalone-tests/terminus.onsignal.fail.js'], (error) => { expect(error.signal).to.eql('SIGINT') expect(responseAssertionsComplete).to.eql(true) done() }) // let the process start up setTimeout(() => { fetch('http://localhost:8000/health') .then(res => { expect(res.status).to.eql(503) responseAssertionsComplete = true }) }, 300) })
it('calls onSendFailureDuringShutdown when sending 503 during shutdown', (done) => { let responseAssertionsComplete = false // We're only truly finished when the response has been analyzed and the forked http process has exited, // freeing up port 8000 for future tests execFile('node', ['lib/standalone-tests/terminus.onsendfailureduringshutdown.js'], (error, stdout) => { expect(error.signal).to.eql('SIGTERM') expect(stdout).to.eql('onSendFailureDuringShutdown\n') expect(responseAssertionsComplete).to.eql(true) done() }) // let the process start up setTimeout(() => { fetch('http://localhost:8000/health') .then(res => { expect(res.status).to.eql(503) responseAssertionsComplete = true }) }, 300) })
child_process.exec('node 16-support.js '+i, function (error, stdout, stderr) { if (error) { console.log(error.stack); console.log('Error code: '+error.code); console.log('Signal received: '+error.signal); } console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); })
it('does NOT call onSendFailureDuringShutdown when sending 503 during failed healthcheck', (done) => { let responseAssertionsComplete = false // We're only truly finished when the response has been analyzed and the forked http process has exited, // freeing up port 8000 for future tests execFile('node', ['lib/standalone-tests/terminus.onsendfailureduringshutdown.failed-health.js'], (error, stdout) => { expect(error.signal).to.eql('SIGTERM') // Here, we expect NOT to see "onSendFailureDuringShutdown" expect(stdout).to.eql('') expect(responseAssertionsComplete).to.eql(true) done() }) // let the process start up setTimeout(() => { fetch('http://localhost:8000/health') .then(res => { expect(res.status).to.eql(503) responseAssertionsComplete = true }) }, 300) })