Skip to content

Commit

Permalink
fix(cpuUsageThrottle): Correctly named handler for debugInfo (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
William Blankenship committed Sep 19, 2017
1 parent cfcdc02 commit 78b0900
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/plugins/cpuUsageThrottle.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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;
12 changes: 12 additions & 0 deletions test/plugins/cpuUsageThrottle.test.js
Expand Up @@ -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();
Expand Down

0 comments on commit 78b0900

Please sign in to comment.