Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cpuUsageThrottle): Correctly named handler for debugInfo #1499

Merged
merged 2 commits into from Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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