From 78b0900b0ffcefa86e541c850d27779c5f656f00 Mon Sep 17 00:00:00 2001 From: William Blankenship Date: Tue, 19 Sep 2017 09:34:55 -0700 Subject: [PATCH] fix(cpuUsageThrottle): Correctly named handler for debugInfo (#1499) --- lib/plugins/cpuUsageThrottle.js | 14 +++++++------- test/plugins/cpuUsageThrottle.test.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/plugins/cpuUsageThrottle.js b/lib/plugins/cpuUsageThrottle.js index c7a2f870c..c03f3365f 100644 --- a/lib/plugins/cpuUsageThrottle.js +++ b/lib/plugins/cpuUsageThrottle.js @@ -77,7 +77,7 @@ var EWMA = require('ewma'); * unit is in ms. Defaults to 250. * @returns {Function} middleware to be registered on server.pre */ -function cpuUsageThrottle (opts) { +function cpuUsageThrottlePlugin (opts) { // Scrub input and populate our configuration assert.object(opts, 'opts'); @@ -150,7 +150,7 @@ function cpuUsageThrottle (opts) { // Kick off updating our _reject value updateReject(); - function onRequest (req, res, next) { + function cpuUsageThrottle (req, res, next) { // Check to see if this request gets rejected. Since, in updateReject, // we calculate a percentage of traffic we are planning to reject, we // can use Math.random() (which picks from a uniform distribution in @@ -186,10 +186,10 @@ function cpuUsageThrottle (opts) { function close () { clearTimeout(self._timeout); } - onRequest.close = close; + cpuUsageThrottle.close = close; // Expose internal plugin state for introspection - Object.defineProperty(onRequest, 'state', { + Object.defineProperty(cpuUsageThrottle, 'state', { get: function () { // We intentionally do not expose ewma since we don't want the user // to be able to update it's configuration, the current state of @@ -215,7 +215,7 @@ function cpuUsageThrottle (opts) { * it follows the same format as the constructor for this plugin. * @returns {undefined} */ - onRequest.update = function update(newOpts) { + cpuUsageThrottle.update = function update(newOpts) { assert.object(newOpts, 'newOpts'); assert.optionalNumber(newOpts.limit, 'newOpts.limit'); assert.optionalNumber(newOpts.max, 'newOpts.max'); @@ -250,7 +250,7 @@ function cpuUsageThrottle (opts) { (self._cpu - self._limit) / (self._max - self._limit); }; - return onRequest; + return cpuUsageThrottle; } -module.exports = cpuUsageThrottle; +module.exports = cpuUsageThrottlePlugin; diff --git a/test/plugins/cpuUsageThrottle.test.js b/test/plugins/cpuUsageThrottle.test.js index b7e89cb83..006ee6162 100644 --- a/test/plugins/cpuUsageThrottle.test.js +++ b/test/plugins/cpuUsageThrottle.test.js @@ -72,6 +72,18 @@ describe('cpuUsageThrottle', function () { done(); }); + it('Unit: Should have proper name', function (done) { + var opts = { + max: 1, + limit: 0.9, + halfLife: 50, + interval: 50 + }; + var plugin = cpuUsageThrottle(opts); + assert.equal(plugin.name, 'cpuUsageThrottle'); + done(); + }); + it('Integration: Should shed load', function (done) { var server = restify.createServer();