There seems to be some kind of concurrency problem with the tests. When running npm test, an UnhandledPromiseRejectionWarning occurs and a test fails. When calling all the tests independently, all of them work.
Limiter with ioredis
.total
✓ should represent the total limit per reset period
.remaining
✓ should represent the number of requests remaining in the reset period
.reset
✓ should represent the next reset time in UTC epoch seconds
when the limit is exceeded
✓ should retain .remaining at 0
✓ should return an increasing reset time after each call (2009ms)
when the duration is exceeded
✓ should reset (3006ms)
when multiple successive calls are made
✓ the next calls should not create again the limiter in Redis
✓ updating the count should keep all TTLs in sync
when trying to decrease before setting value
✓ should create with ttl when trying to decrease
when multiple concurrent clients modify the limit
(node:95644) UnhandledPromiseRejectionWarning: AssertionError: expected 2 to be 0
at Assertion.fail (/Users/nkaiser/Code/github/async-ratelimiter/node_modules/should/cjs/should.js:275:17)
at Assertion.value (/Users/nkaiser/Code/github/async-ratelimiter/node_modules/should/cjs/should.js:356:19)
at /Users/nkaiser/Code/github/async-ratelimiter/test/index.js:181:33
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:95644) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:95644) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1) should prevent race condition and properly set the expected value
9 passing (5s)
1 failing
1) Limiter with ioredis
when multiple concurrent clients modify the limit
should prevent race condition and properly set the expected value:
AssertionError: expected 4 to be 5
+ expected - actual
-4
+5
at Assertion.fail (node_modules/should/cjs/should.js:275:17)
at Assertion.value (node_modules/should/cjs/should.js:356:19)
at Context.<anonymous> (test/index.js:235:31)
at process._tickCallback (internal/process/next_tick.js:68:7)
There seems to be some kind of concurrency problem with the tests. When running
npm test
, an UnhandledPromiseRejectionWarning occurs and a test fails. When calling all the tests independently, all of them work.