From 8c695a262b0f98284b504649dc75440c8b35bae9 Mon Sep 17 00:00:00 2001 From: Sandro Martini <sandro.martini@ynap.com> Date: Fri, 16 Nov 2018 00:51:09 +0100 Subject: [PATCH 1/5] update to latest fastify and all plugin to latest release; configure tap tests to run in parallel; fix lint errors --- index.js | 4 ++-- package.json | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index b135750..5f6e914 100644 --- a/index.js +++ b/index.js @@ -32,8 +32,8 @@ function underPressure (fastify, opts, next) { type: 'object', properties: { status: { type: 'string' } - }} - } + } + } } }, handler: onStatus }) diff --git a/package.json b/package.json index 6784a2c..6e2a0d3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "lint": "standard | snazzy", - "unit": "tap test.js", + "unit": "tap -J test.js", "test": "npm run lint && npm run unit", "coverage": "npm run unit -- --cov --coverage-report=html" }, @@ -26,14 +26,14 @@ "author": "Tomas Della Vedova - @delvedor (http://delved.org)", "license": "MIT", "dependencies": { - "fastify-plugin": "^1.2.0" + "fastify-plugin": "^1.2.1" }, "devDependencies": { - "fastify": "^1.7.0", + "fastify": "^1.13.0", "pre-commit": "^1.2.2", - "simple-get": "^3.0.2", - "snazzy": "^7.1.1", - "standard": "^11.0.1", - "tap": "^12.0.1" + "simple-get": "^3.0.3", + "snazzy": "^8.0.0", + "standard": "^12.0.1", + "tap": "^12.1.0" } } From 9897cd7197a0f651cb4d47f368e024668cbbf588 Mon Sep 17 00:00:00 2001 From: Sandro Martini <sandro.martini@ynap.com> Date: Fri, 16 Nov 2018 01:04:27 +0100 Subject: [PATCH 2/5] update tests to use the (err, address) function in listen, to simplify test urls --- test.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/test.js b/test.js index c43010e..fa28948 100644 --- a/test.js +++ b/test.js @@ -18,14 +18,15 @@ test('Should return 503 on maxEventLoopDelay', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) + fastify.server.unref() // Increased to prevent Travis to fail process.nextTick(() => sleep(1000)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -52,13 +53,14 @@ test('Should return 503 on maxHeapUsedBytes', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -85,13 +87,14 @@ test('Should return 503 on maxRssBytes', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -120,13 +123,14 @@ test('Custom message and retry after header', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -158,14 +162,15 @@ test('memoryUsage name space', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) t.is(typeof fastify.memoryUsage, 'function') + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) @@ -188,14 +193,15 @@ test('memoryUsage name space (without check)', t => { reply.send({ hello: 'world' }) }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) t.is(typeof fastify.memoryUsage, 'function') + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + url: `${address}` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) @@ -213,13 +219,14 @@ test('Expose status route', t => { exposeStatusRoute: true }) - fastify.listen(0, err => { + fastify.listen(0, (err, address) => { t.error(err) + fastify.server.unref() process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: 'http://localhost:' + fastify.server.address().port + '/status' + url: `${address}/status` }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) From 9beef4e36b26d788159cce8793753b7d4fd614ec Mon Sep 17 00:00:00 2001 From: Sandro Martini <sandro.martini@ynap.com> Date: Fri, 16 Nov 2018 01:44:00 +0100 Subject: [PATCH 3/5] update requirements to fastify 1.1.0 or later, like in fastify-plugin release used (anyway not 0.x anymore) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5f6e914..bdca92f 100644 --- a/index.js +++ b/index.js @@ -110,6 +110,6 @@ function now () { } module.exports = fp(underPressure, { - fastify: '>=0.39.0', + fastify: '^1.1.0', name: 'under-pressure' }) From 550b1768951dfdad96897c5e5da701ca8f7edd42 Mon Sep 17 00:00:00 2001 From: Sandro Martini <sandro.martini@ynap.com> Date: Fri, 16 Nov 2018 15:23:11 +0100 Subject: [PATCH 4/5] remove template strings where not really needed --- test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test.js b/test.js index fa28948..cac9eda 100644 --- a/test.js +++ b/test.js @@ -26,7 +26,7 @@ test('Should return 503 on maxEventLoopDelay', t => { process.nextTick(() => sleep(1000)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -60,7 +60,7 @@ test('Should return 503 on maxHeapUsedBytes', t => { process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -94,7 +94,7 @@ test('Should return 503 on maxRssBytes', t => { process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -130,7 +130,7 @@ test('Custom message and retry after header', t => { process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 503) @@ -170,7 +170,7 @@ test('memoryUsage name space', t => { process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) @@ -201,7 +201,7 @@ test('memoryUsage name space (without check)', t => { process.nextTick(() => sleep(500)) sget({ method: 'GET', - url: `${address}` + url: address }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) From b9543634cd373ca5646af6b15a286e59112607e3 Mon Sep 17 00:00:00 2001 From: Sandro Martini <sandro.martini@gmail.com> Date: Mon, 19 Nov 2018 18:43:45 +0100 Subject: [PATCH 5/5] update README with Fastify minimum release required --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d97ae3b..3c23f91 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ Measure process load with automatic handling of *"Service Unavailable"* plugin for Fastify. It can check `maxEventLoopDelay`, `maxHeapUsedBytes` and `maxRssBytes` values. +<a name="requirements"></a> +## Requirements + +Fastify ^1.1.0 . + <a name="install"></a> ## Install ```