Skip to content
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

[Feature Request] Support for tests #15

Open
SandroDamilano opened this issue Sep 19, 2022 · 2 comments
Open

[Feature Request] Support for tests #15

SandroDamilano opened this issue Sep 19, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@SandroDamilano
Copy link

tl;dr: It would be great to provide a way to run tests without worrying the gem will prevent consecutive runs to be successful. This could be provided in the form of a specific method/implementation enhancement or at least with some guidance in the docs.

Problem

I've experienced in my project that some tests when run twice in a row they fail in the second run. This happens because RateLimit.throttle! is failing the second time.
To solve the problem, as we're using Redis, I've added Redis.new.flushall to the before statement in our rails_helper.

Solution

It would be great if there was a way to configure the gem itself to prevent this from happening, like setting it to test mode.
Otherwise, maybe at least adding some guidance to the docs on how to deal with such scenario would also be fine.

@SandroDamilano SandroDamilano added the enhancement New feature or request label Sep 19, 2022
@dhruvCW
Copy link
Contributor

dhruvCW commented Sep 19, 2022

It would be great if there was a way to configure the gem itself to prevent this from happening, like setting it to test mode.

I don't know how this would work, especially since test scenarios can be very diverse.

IMO a good option would be to introduce

RateLimit.clear_all_counters

which for now would just wrap RateLimit.config.redis.flushall but abstract away the internal mechanisms from the tests.

@aka-momo
Copy link
Contributor

aka-momo commented Oct 4, 2022

Thanks for the request. I'm going to add some new issues to support multiple cache adaptors and improvement for the overall caching layer. Then we can pick this issue during that milestone 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants