-
-
Notifications
You must be signed in to change notification settings - Fork 2
Jest and TS Config with initial Token Bucket tests #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments moved to below
jondeweydev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted comments, mainly suggestions.
updated timestamps to use UNIX format
Summary
Type of ChangePlease delete options that are not relevant.
Issues
Evidence |
| const tokenCountFull = await getBucketFromClient(client, user1); | ||
| expect(tokenCountFull).toBe(CAPACITY - withdraw5); | ||
|
|
||
| // Bucket partially full but enough time has elapsed to fill the bucket since the last request and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break these out into separate tests instead of having one test for all of these variations on situations with allowed requests
| timestamp + 1000 * (CAPACITY - initial), | ||
| initial + partialWithdraw | ||
| ) | ||
| ).toBe(CAPACITY - (initial + partialWithdraw)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These case reads to me like:
line 58 - set token bucket to have 6 tokens
line 60 - process request withdrawing 7 tokens (6+1)
line 65 - expect the 3 tokens in the bucket (10 - (6 + 1)) when I think there will be -1 tokens in the bucket
I'm having a hard time following all this redis stuff so I might be wrong. Need more time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be processRequest().tokens to access the tokens property on the returned object from processRequest method. This goes for a lot of the tests in this area. Maybe also assert that processRequest().sucess is true/false as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 62 is saying that enough time has elapsed to refill the bucket since the last request (4000 ms). So when we withdraw 7 tokens there should be 3 remaining. Was trying to get after a case where the bucket fills enough between requests.
evanmcneely
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. I made one small followup comment on the optional parameters in typescript.

Initial jest and tsconfig.
Closes #4 with token bucket testing
Closes #9 with a class spec for RateLimiters