diff --git a/spec/support/shared_examples/requests/rack_attack_shared_examples.rb b/spec/support/shared_examples/requests/rack_attack_shared_examples.rb index d15c88244f84b72620c1540b0b26865b11f40ac0..4f7dc243cafaec1b195ed1e0929d5bf105e08210 100644 --- a/spec/support/shared_examples/requests/rack_attack_shared_examples.rb +++ b/spec/support/shared_examples/requests/rack_attack_shared_examples.rb @@ -96,6 +96,10 @@ end it 'allows requests after throttling and then waiting for the next period' do + # ensure we don't tick over to the next second while hitting this period's rate limit + # before calculating the time for the next period + next_period = period.from_now + requests_per_period.times do make_request(request_args) expect(response).not_to have_gitlab_http_status(:too_many_requests) @@ -103,7 +107,7 @@ expect_rejection { make_request(request_args) } - travel_to(period.from_now) do + travel_to(next_period) do requests_per_period.times do make_request(request_args) expect(response).not_to have_gitlab_http_status(:too_many_requests)