Fix #277
This commit is contained in:
parent
c2cd04f760
commit
6aecb32c89
3 changed files with 65 additions and 6 deletions
52
tests/rateLimiter.js
Normal file
52
tests/rateLimiter.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
var $util = require('../lib/utilities.js');
|
||||
|
||||
function testBurst() {
|
||||
var lim = $util.newRateLimiter();
|
||||
var params = {
|
||||
burst: 10,
|
||||
sustained: 2
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (lim.throttle(params)) {
|
||||
console.log("[FAIL] Burst: Unexpected throttle");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lim.throttle(params)) {
|
||||
console.log("[FAIL] Burst: didn't throttle after exceeding burst amount");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("[PASS] Burst");
|
||||
}
|
||||
|
||||
function testBurstAndWait() {
|
||||
var lim = $util.newRateLimiter();
|
||||
var params = {
|
||||
burst: 10,
|
||||
sustained: 2
|
||||
};
|
||||
|
||||
for (var i = 0; i < 9; i++) {
|
||||
if (lim.throttle(params)) {
|
||||
console.log("[FAIL] Burst & Wait: Unexpected throttle");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait a while and try some more
|
||||
setTimeout(function () {
|
||||
for (var i = 9; i < 17; i++) {
|
||||
if (lim.throttle(params)) {
|
||||
console.log("[FAIL] Burst & Wait: Unexpected throttle");
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log("[PASS] Burst & Wait");
|
||||
}, 6000);
|
||||
}
|
||||
|
||||
testBurst();
|
||||
testBurstAndWait();
|
||||
Loading…
Add table
Add a link
Reference in a new issue