limitd-client
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "limitd-client", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "limitd client for node.js", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"disyuntor": "~1.2.1", | ||
"disyuntor": "^1.2.2", | ||
"length-prefixed-message": "^3.0.3", | ||
@@ -15,0 +15,0 @@ "length-prefixed-stream": "~1.4.0", |
@@ -5,30 +5,63 @@ const MockServer = require('./MockServer'); | ||
const assert = require('chai').assert; | ||
const async = require('async'); | ||
describe('circuit breaker', function () { | ||
describe.only('circuit breaker', function () { | ||
const server = new MockServer({ port }); | ||
var client; | ||
before(done => server.listen(done)); | ||
beforeEach(done => { | ||
client = new LimitdClient({ | ||
hosts: [`limitd://localhost:${port}`], | ||
breaker: { | ||
cooldown: 200, | ||
timeout: 100, | ||
maxFailures: 1, | ||
} | ||
}, done); | ||
}); | ||
it('should fail fast once we reach the threashold', function (done) { | ||
const server = new MockServer({ port }); | ||
const breaker_errors = []; | ||
server.once('request', () => {}).listen(function () { | ||
var client = new LimitdClient({ | ||
hosts: [`limitd://localhost:${port}`], | ||
breaker: { | ||
timeout: 100, | ||
maxFailures: 1, | ||
} | ||
}, function () { | ||
client.once('breaker_error', (err) => breaker_errors.push(err)); | ||
client.once('breaker_error', (err) => breaker_errors.push(err)); | ||
client.take('ip', '1232.312.error', 1, function (err1) { | ||
assert.equal(err1.message, 'limitd.request: specified timeout of 100ms was reached'); | ||
client.take('ip', '1232.312.error', 1, function (err2) { | ||
assert.equal(err2.message, 'limitd.request: the circuit-breaker is open'); | ||
assert.equal(breaker_errors.length, 1); | ||
assert.equal(breaker_errors[0], err2); | ||
done(); | ||
}); | ||
}); | ||
client.take('ip', '1232.312.error', 1, function (err1) { | ||
assert.equal(err1.message, 'limitd.request: specified timeout of 100ms was reached'); | ||
const startTime = Date.now(); | ||
client.take('ip', '1232.312.error', 1, function (err2) { | ||
assert.equal(err2.message, 'limitd.request: the circuit-breaker is open'); | ||
assert.equal(breaker_errors.length, 1); | ||
assert.equal(breaker_errors[0], err2); | ||
assert.closeTo(Date.now() - startTime, 0, 10); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should only allow one request on half-open state', function (done) { | ||
const breaker_errors = []; | ||
client.once('breaker_error', (err) => breaker_errors.push(err)); | ||
client.take('ip', '1232.312.error', 1, (err1) => { | ||
assert.equal(err1.message, 'limitd.request: specified timeout of 100ms was reached'); | ||
setTimeout(() => { | ||
async.parallel([ | ||
(done) => client.take('ip', 'err', (err) => done(null, err)), | ||
(done) => client.take('ip', 'err', (err) => done(null, err)) | ||
], (err, errs) => { | ||
if (err) { return done(err); } | ||
assert.equal(errs[0].message, 'limitd.request: specified timeout of 100ms was reached'); | ||
assert.equal(errs[1].message, 'limitd.request: the circuit-breaker is open'); | ||
done(); | ||
}); | ||
}, 205); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34000
852
+ Addeddisyuntor@1.3.0(transitive)
- Removeddisyuntor@1.2.3(transitive)
Updateddisyuntor@^1.2.2