ejfinneran / ratelimit

A Redis-backed rate limiter written in Ruby
MIT License
257 stars 55 forks source link

Raise error if interval is larger than bucket_span #37

Open phillipp opened 3 years ago

phillipp commented 3 years ago

I recently found that we had a lot of places where bucket_span did not span the whole interval we checked when using count or exceeded?, like when checking a rate limit for the last 24 hours without modifying bucket_span in the initualizer.

The failure is silent and I could imagine that a lot of tests would not catch this, if the adds are not wrapped in timecop etc.

I'd suggest that when the count method receives a options[:interval] larger than options[:bucket_span] an error is raised, so the problem is uncovered.

Does that make any sense?