Fix test
This commit is contained in:
parent
29b904483e
commit
721f6f9c97
1 changed files with 20 additions and 20 deletions
|
@ -7,18 +7,6 @@ RSpec.describe Rack::Attack, type: :request do
|
||||||
Rails.application
|
Rails.application
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_context 'with throttled endpoint base' do
|
|
||||||
before do
|
|
||||||
# Rack::Attack periods are not rolling, so avoid flaky tests by setting the time in a way
|
|
||||||
# to avoid crossing period boundaries.
|
|
||||||
|
|
||||||
# The code Rack::Attack uses to set periods is the following:
|
|
||||||
# https://github.com/rack/rack-attack/blob/v6.7.0/lib/rack/attack/cache.rb#L70-L72
|
|
||||||
# So we want to minimize `Time.now.to_i % period`
|
|
||||||
|
|
||||||
travel_to Time.zone.at(counter_prefix * period.seconds)
|
|
||||||
end
|
|
||||||
|
|
||||||
def below_limit
|
def below_limit
|
||||||
limit - 1
|
limit - 1
|
||||||
end
|
end
|
||||||
|
@ -38,6 +26,18 @@ RSpec.describe Rack::Attack, type: :request do
|
||||||
def increment_counter
|
def increment_counter
|
||||||
described_class.cache.count("#{throttle}:#{discriminator}", period)
|
described_class.cache.count("#{throttle}:#{discriminator}", period)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_context 'with throttled endpoint base' do
|
||||||
|
before do
|
||||||
|
# Rack::Attack periods are not rolling, so avoid flaky tests by setting the time in a way
|
||||||
|
# to avoid crossing period boundaries.
|
||||||
|
|
||||||
|
# The code Rack::Attack uses to set periods is the following:
|
||||||
|
# https://github.com/rack/rack-attack/blob/v6.7.0/lib/rack/attack/cache.rb#L70-L72
|
||||||
|
# So we want to minimize `Time.now.to_i % period`
|
||||||
|
|
||||||
|
travel_to Time.zone.at(counter_prefix * period.seconds)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'throttled endpoint' do
|
shared_examples 'throttled endpoint' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue