diff --git a/lib/plugins/inflightRequestThrottle.js b/lib/plugins/inflightRequestThrottle.js index 04096a0fe..8fedd72ab 100644 --- a/lib/plugins/inflightRequestThrottle.js +++ b/lib/plugins/inflightRequestThrottle.js @@ -30,7 +30,7 @@ function inflightRequestThrottle (opts) { assert.func(opts.server.inflightRequests, 'opts.server.inflightRequests'); if (opts.err !== undefined && opts.err !== null) { - assert.ok(opts.err instanceof Error, 'opts.res must be an error'); + assert.ok(opts.err instanceof Error, 'opts.err must be an error'); assert.optionalNumber(opts.err.statusCode, 'opts.err.statusCode'); } @@ -48,17 +48,14 @@ function inflightRequestThrottle (opts) { inflightRequests: inflightRequests, limit: self._limit }, 'maximum inflight requests exceeded, rejecting request'); - return res.send(self._err); + res.send(self._err); + return next(false); } return next(); } - // We need to bind in order to keep our `this` context when passed back - // out of the constructor. return onRequest; } -inflightRequestThrottle.prototype.onRequest = - module.exports = inflightRequestThrottle; diff --git a/test/plugins/inflightRequestThrottle.test.js b/test/plugins/inflightRequestThrottle.test.js index ee28b8b63..94d3dcc97 100644 --- a/test/plugins/inflightRequestThrottle.test.js +++ b/test/plugins/inflightRequestThrottle.test.js @@ -25,9 +25,8 @@ describe('inlfightRequestThrottle', function () { assert(body instanceof Error, 'Defaults to error body'); done(); } - function next () { - assert(false, 'Should not call next'); - done(); + function next (cont) { + assert.isFalse(cont, 'Should call next with false'); } function trace () { logged = true; @@ -48,7 +47,6 @@ describe('inlfightRequestThrottle', function () { } function next () { assert(false, 'Should not call next'); - done(); } var fakeReq = { log : { trace: function () {} } }; plugin(fakeReq, { send: send }, next); @@ -59,10 +57,9 @@ describe('inlfightRequestThrottle', function () { var plugin = inflightRequestThrottle(opts); function send () { assert(false, 'Should not call send'); - done(); } - function next () { - assert(true, 'Should call next'); + function next (cont) { + assert.isUndefined(cont, 'Should call next'); done(); } var fakeReq = { log : { trace: function () {} } }; @@ -116,7 +113,10 @@ describe('inlfightRequestThrottle', function () { 'InternalServerError', 'Default err returned'); assert.equal(res.statusCode, 555, 'Default shed status code returned'); - RES.send(200); + + if (RES) { + RES.send(200); + } }); }); });