@godaddy/terminus
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -53,3 +53,3 @@ 'use strict' | ||
server.removeListener('request', listener) | ||
server.on('request', (req, res) => { | ||
server.on('request', async (req, res) => { | ||
if (healthChecks[req.url]) { | ||
@@ -59,10 +59,10 @@ if (state.isShuttingDown) { | ||
} | ||
healthChecks[req.url]() | ||
.then((info) => { | ||
sendSuccess(res, info) | ||
}) | ||
.catch((error) => { | ||
logger('healthcheck failed', error) | ||
sendFailure(res, error.causes) | ||
}) | ||
let info | ||
try { | ||
info = await healthChecks[req.url]() | ||
} catch (error) { | ||
logger('healthcheck failed', error) | ||
return sendFailure(res, error.causes) | ||
} | ||
sendSuccess(res, info) | ||
} else { | ||
@@ -82,17 +82,16 @@ listener(req, res) | ||
function cleanup (signal) { | ||
async function cleanup (signal) { | ||
if (!state.isShuttingDown) { | ||
state.isShuttingDown = true | ||
beforeShutdown() | ||
.then(() => asyncServerStop()) | ||
.then(() => onSignal()) | ||
.then(() => onShutdown()) | ||
.then(() => { | ||
signals.forEach(sig => process.removeListener(sig, cleanup)) | ||
process.kill(process.pid, signal) | ||
}) | ||
.catch((error) => { | ||
logger('error happened during shutdown', error) | ||
process.exit(1) | ||
}) | ||
try { | ||
await beforeShutdown() | ||
await asyncServerStop() | ||
await onSignal() | ||
await onShutdown() | ||
signals.forEach(sig => process.removeListener(sig, cleanup)) | ||
process.kill(process.pid, signal) | ||
} catch (error) { | ||
logger('error happened during shutdown', error) | ||
process.exit(1) | ||
} | ||
} | ||
@@ -99,0 +98,0 @@ } |
@@ -23,16 +23,12 @@ 'use strict' | ||
describe('supports onHealthcheck for the healthcheck route', () => { | ||
it('but keeps all the other endpoints', (done) => { | ||
it('but keeps all the other endpoints', async () => { | ||
createTerminus(server, {}) | ||
server.listen(8000) | ||
fetch('http://localhost:8000') | ||
.then(res => res.text()) | ||
.then(responseText => { | ||
expect(responseText).to.eql('hello') | ||
done() | ||
}) | ||
.catch(done) | ||
const response = await fetch('http://localhost:8000') | ||
const text = await response.text() | ||
expect(text).to.eql('hello') | ||
}) | ||
it('returns 200 on resolve', (done) => { | ||
it('returns 200 on resolve', async () => { | ||
let onHealthCheckRan = false | ||
@@ -50,14 +46,10 @@ | ||
fetch('http://localhost:8000/health') | ||
.then(res => { | ||
expect(res.status).to.eql(200) | ||
expect(res.headers.has('Content-Type')).to.eql(true) | ||
expect(res.headers.get('Content-Type')).to.eql('application/json') | ||
expect(onHealthCheckRan).to.eql(true) | ||
done() | ||
}) | ||
.catch(done) | ||
const response = await fetch('http://localhost:8000/health') | ||
expect(response.status).to.eql(200) | ||
expect(response.headers.has('Content-Type')).to.eql(true) | ||
expect(response.headers.get('Content-Type')).to.eql('application/json') | ||
expect(onHealthCheckRan).to.eql(true) | ||
}) | ||
it('includes info on resolve', (done) => { | ||
it('includes info on resolve', async () => { | ||
let onHealthCheckRan = false | ||
@@ -77,23 +69,17 @@ | ||
fetch('http://localhost:8000/health') | ||
.then(res => { | ||
expect(res.status).to.eql(200) | ||
expect(res.headers.has('Content-Type')).to.eql(true) | ||
expect(res.headers.get('Content-Type')).to.eql('application/json') | ||
expect(onHealthCheckRan).to.eql(true) | ||
return res.json() | ||
}) | ||
.then(json => { | ||
expect(json).to.deep.eql({ | ||
status: 'ok', | ||
info: { | ||
version: '1.0.0' | ||
} | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
const res = await fetch('http://localhost:8000/health') | ||
expect(res.status).to.eql(200) | ||
expect(res.headers.has('Content-Type')).to.eql(true) | ||
expect(res.headers.get('Content-Type')).to.eql('application/json') | ||
expect(onHealthCheckRan).to.eql(true) | ||
const json = await res.json() | ||
expect(json).to.deep.eql({ | ||
status: 'ok', | ||
info: { | ||
version: '1.0.0' | ||
} | ||
}) | ||
}) | ||
it('returns 503 on reject', (done) => { | ||
it('returns 503 on reject', async () => { | ||
let onHealthCheckRan = false | ||
@@ -115,13 +101,9 @@ let loggerRan = false | ||
fetch('http://localhost:8000/health') | ||
.then(res => { | ||
expect(res.status).to.eql(503) | ||
expect(onHealthCheckRan).to.eql(true) | ||
expect(loggerRan).to.eql(true) | ||
done() | ||
}) | ||
.catch(done) | ||
const res = await fetch('http://localhost:8000/health') | ||
expect(res.status).to.eql(503) | ||
expect(onHealthCheckRan).to.eql(true) | ||
expect(loggerRan).to.eql(true) | ||
}) | ||
it('includes error on reject', (done) => { | ||
it('includes error on reject', async () => { | ||
let onHealthCheckRan = false | ||
@@ -145,21 +127,15 @@ | ||
fetch('http://localhost:8000/health') | ||
.then(res => { | ||
expect(res.status).to.eql(503) | ||
expect(onHealthCheckRan).to.eql(true) | ||
return res.json() | ||
}) | ||
.then(json => { | ||
expect(json).to.deep.eql({ | ||
status: 'error', | ||
error: { | ||
fornite: 'client down', | ||
redis: { | ||
disk: 100 | ||
} | ||
} | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
const res = await fetch('http://localhost:8000/health') | ||
expect(res.status).to.eql(503) | ||
expect(onHealthCheckRan).to.eql(true) | ||
const json = await res.json() | ||
expect(json).to.deep.eql({ | ||
status: 'error', | ||
error: { | ||
fornite: 'client down', | ||
redis: { | ||
disk: 100 | ||
} | ||
} | ||
}) | ||
}) | ||
@@ -166,0 +142,0 @@ |
{ | ||
"name": "@godaddy/terminus", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34706
815