redis-gcra
Advanced tools
Comparing version
@@ -5,2 +5,10 @@ # Edge Agent Changelog | ||
## 0.2.0 - 2019-07-18 | ||
- Stop rounding remaining tokens | ||
- Update development/test dependencies | ||
- Add Node 11 & 12 to travis.yml | ||
*** | ||
## 0.1.1 - 2018-10-22 | ||
@@ -17,2 +25,2 @@ | ||
- Initial release | ||
- Initial release |
{ | ||
"name": "redis-gcra", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Rate limiting based on Generic Cell Rate Algorithm", | ||
@@ -46,5 +46,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@losant/eslint-config-losant": "^1.3.4", | ||
"husky": "^1.1.2", | ||
"lint-staged": "^7.3.0", | ||
"@losant/eslint-config-losant": "^1.3.6", | ||
"husky": "^3.0.0", | ||
"lint-staged": "^9.2.0", | ||
"mocha": "^5.2.0", | ||
@@ -51,0 +51,0 @@ "should": "^13.2.3" |
@@ -19,2 +19,36 @@ const Redis = require('ioredis'); | ||
it('should not round your tokens', async () => { | ||
const opts = { key: 'testKey', burst: 1, rate: 1, period: 1000, cost: 1 }; | ||
let result = await this.limiter.limit(opts); | ||
result.limited.should.equal(false); | ||
result.remaining.should.equal(0); | ||
result.retryIn.should.equal(0); | ||
result.resetIn.should.be.within(990, 1000); | ||
await new Promise((fulfill) => { | ||
setTimeout(fulfill, result.resetIn * 0.75); // wait 3/4 of the time | ||
}); | ||
result = await this.limiter.limit(opts); | ||
result.limited.should.equal(true); | ||
result.remaining.should.equal(0); | ||
result.retryIn.should.be.within(100, 250); | ||
result.resetIn.should.be.within(100, 250); | ||
result = await this.limiter.peek(opts); | ||
result.limited.should.equal(true); | ||
result.remaining.should.equal(0); | ||
result.resetIn.should.be.within(100, 250); | ||
await new Promise((fulfill) => { | ||
setTimeout(fulfill, result.resetIn); // wait the rest of the time | ||
}); | ||
result = await this.limiter.limit(opts); | ||
result.limited.should.equal(false); | ||
result.remaining.should.equal(0); | ||
result.retryIn.should.equal(0); | ||
result.resetIn.should.be.within(990, 1000); | ||
}); | ||
it('should perform basic limit and regen', async () => { | ||
@@ -21,0 +55,0 @@ const opts = { key: 'testKey', burst: 4, rate: 1, period: 500, cost: 2 }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
122126
2.56%418
7.18%