Socket
Socket
Sign inDemoInstall

bottleneckp

Package Overview
Dependencies
0
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.2 to 1.1.3

10

lib/Bottleneck.js

@@ -91,2 +91,12 @@ var PriorityQueue = function(size) {

Bottleneck.prototype.setRateLimit = function(rateLimit) {
if(isNaN(rateLimit)) {
throw "rateLimit must be a number";
}
this.rateLimit = parseInt(rateLimit);
if(this.rateLimit > 0) {
this.maxConcurrent = 1;
}
}
Bottleneck.prototype.submit = function(options, clientCallback) {

@@ -93,0 +103,0 @@ var self = this;

2

package.json
{
"name": "bottleneckp",
"version": "1.1.2",
"version": "1.1.3",
"description": "asynchronous rate limiter with priority",

@@ -5,0 +5,0 @@ "main": "./lib/Bottleneck.js",

@@ -1,5 +0,5 @@

describe('General', function () {
describe('constructor', function () {
describe('General', function() {
describe('constructor', function() {
it('_tasksRunning and _waitingClients should be 0 at initial state', function (done) {
it('_tasksRunning and _waitingClients should be 0 at initial state', function(done) {
var c = new Bottleneck(10, 0)

@@ -11,3 +11,3 @@ console.assert(c._tasksRunning === 0)

it('maxConcurrent and rateLimit should be equal to those passed to the constructor when not conflictive', function (done) {
it('maxConcurrent and rateLimit should be equal to those passed to the constructor when not conflictive', function(done) {
var c = new Bottleneck(10, 0)

@@ -19,3 +19,3 @@ console.assert(c.rateLimit === 0)

it('maxConcurrent should be 1 if rateLimit is not 0', function (done) {
it('maxConcurrent should be 1 if rateLimit is not 0', function(done) {
var c = new Bottleneck(10, 1000)

@@ -27,3 +27,3 @@ console.assert(c.rateLimit === 1000)

it('priorityRange should be 1 in default', function (done) {
it('priorityRange should be 1 in default', function(done) {
var c = new Bottleneck(10, 1000)

@@ -34,3 +34,3 @@ console.assert(c._priorityRange === 1)

it('defaultPriority should be half of priorityRange if not set', function (done) {
it('defaultPriority should be half of priorityRange if not set', function(done) {
var c1 = new Bottleneck(1, 1000, 5)

@@ -48,5 +48,5 @@ console.assert(c1._defaultPriority === 2)

describe('priority', function () {
describe('priority', function() {
it('should work when passed invalid priority', function (done) {
it('should work when passed invalid priority', function(done) {
var c = makeTest(1, 250, 10)

@@ -60,9 +60,9 @@ c.limiter.submit(-1, c.job(1))

c.limiter.submit(10, c.last(4, {
checkResults:[1,2,3,4],
checkDuration:750,
done:done
checkResults: [1, 2, 3, 4],
checkDuration: 750,
done: done
}))
})
it('should work properly with priority and non-zero rateLimit', function (done) {
it('should work properly with priority and non-zero rateLimit', function(done) {
var c = makeTest(1, 250, 10)

@@ -72,5 +72,5 @@ c.limiter.submit(5, c.job(1))

c.limiter.submit(9, c.last(2, {
checkResults:[1,5,4,3,2],
checkDuration:1000,
done:done
checkResults: [1, 5, 4, 3, 2],
checkDuration: 1000,
done: done
}))

@@ -86,3 +86,3 @@ console.assert(c.size() === 1)

it('should work properly with priority and zero rateLimit', function (done) {
it('should work properly with priority and zero rateLimit', function(done) {
var c = makeTest(10, 0, 10)

@@ -114,5 +114,5 @@ c.limiter.submit(5, c.job(1))

c.limiter.submit(9, c.last(13, {
checkResults:[1,2,3,4,5,6,7,8,9,10,12,11,13],
checkDuration:0,
done:done
checkResults: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 11, 13],
checkDuration: 0,
done: done
}))

@@ -133,11 +133,20 @@ console.assert(c.size() === 3)

c.cluster.key('1').submit(5, c.last('1', 5, {
checkResults:[
{in:'2',out:null,value:4},
{in:'1',out:'2',value:2},
{in:'1',out:'2',value:3},
{in:'1',out:null,value:1},
{in:'1',out:'2',value:5}
],
checkDuration:800,
done:done
checkResults: [{ in : '2',
out: null,
value: 4
}, { in : '1',
out: '2',
value: 2
}, { in : '1',
out: '2',
value: 3
}, { in : '1',
out: null,
value: 1
}, { in : '1',
out: '2',
value: 5
}],
checkDuration: 800,
done: done
}))

@@ -164,20 +173,49 @@ })

c.cluster.key('1').submit(5, c.last('1', 4, {
checkResults:[
{in:'1',out:null,value:1},
{in:'2',out:null,value:3},
{in:'1',out:null,value:2},
{in:'1',out:null,value:4}
],
checkDuration:700,
done:function() {
console.assert(c.cluster.empty === true)
console.assert(c.cluster.waitingClients === 0)
console.assert(c.cluster.unfinishedClients === 0)
done()
}
checkResults: [{ in : '1',
out: null,
value: 1
}, { in : '2',
out: null,
value: 3
}, { in : '1',
out: null,
value: 2
}, { in : '1',
out: null,
value: 4
}],
checkDuration: 700,
done: function() {
console.assert(c.cluster.empty === true)
console.assert(c.cluster.waitingClients === 0)
console.assert(c.cluster.unfinishedClients === 0)
done()
}
}))
console.assert(c.cluster.waitingClients === 2)
})
console.assert(c.cluster.waitingClients === 2)
})
})
describe('Bottleneck property', function() {
it('should be able to change rateLimit after initialization', function() {
var bottleneck = new Bottleneck(10, 0, 10, 5);
console.assert(bottleneck.maxConcurrent === 10);
console.assert(bottleneck.rateLimit === 0);
bottleneck.setRateLimit(1000);
console.assert(bottleneck.maxConcurrent === 1);
console.assert(bottleneck.rateLimit === 1000);
})
it('should throw error when set rateLimit to non-number value', function() {
var bottleneck = new Bottleneck(10, 0, 10, 5);
var error = null;
try {
bottleneck.setRateLimit('NaN');
} catch(e) {
error = e;
}
console.assert(error !== null);
})
})
})
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc