Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

limitd-client

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limitd-client - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

4

package.json
{
"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);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc