Commit d0b32815 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix flaky specs due to rate limiter change

We need to freeze time in these specs so that we know the multiple
requests we're making fall into the same time bucket used by the rate
limiter
parent d0871fac
......@@ -493,12 +493,12 @@ RSpec.describe Groups::EpicsController do
end
end
context 'when the endpoint receives requests above the limit' do
context 'when the endpoint receives requests above the limit', :freeze_time, :clean_gitlab_redis_rate_limiting do
before do
stub_application_setting(issues_create_limit: 5)
end
it 'prevents from creating more epics', :request_store do
it 'prevents from creating more epics' do
5.times { post :create, params: { group_id: group, epic: { title: 'new epic', description: 'description' } } }
post :create, params: { group_id: group, epic: { title: 'new epic', description: 'description' } }
......
......@@ -1408,7 +1408,7 @@ RSpec.describe Projects::IssuesController do
end
end
context 'when the endpoint receives requests above the limit' do
context 'when the endpoint receives requests above the limit', :freeze_time, :clean_gitlab_redis_rate_limiting do
before do
stub_application_setting(issues_create_limit: 5)
end
......
......@@ -259,7 +259,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end
end
context 'when rate limiting is in effect', :clean_gitlab_redis_cache do
context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do
let(:receiver) { Gitlab::Email::Receiver.new(email_raw) }
subject { 2.times { receiver.execute } }
......@@ -271,19 +271,15 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
context 'when too many requests are sent by one user' do
it 'raises an error' do
freeze_time do
expect { subject }.to raise_error(RateLimitedService::RateLimitedError)
end
end
it 'creates 1 issue' do
freeze_time do
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
end
context 'when requests are sent by different users' do
let(:email_raw_2) { email_fixture('emails/service_desk_forwarded.eml') }
......@@ -295,12 +291,10 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end
it 'creates 2 issues' do
freeze_time do
expect { subject }.to change { Issue.count }.by(2)
end
end
end
end
context 'when limit is higher than sent emails' do
before do
......@@ -308,12 +302,10 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end
it 'creates 2 issues' do
freeze_time do
expect { subject }.to change { Issue.count }.by(2)
end
end
end
end
describe '#can_handle?' do
let(:mail) { Mail::Message.new(email_raw) }
......
......@@ -302,7 +302,7 @@ RSpec.describe Issues::CreateService do
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
end
context 'when rate limiting is in effect', :clean_gitlab_redis_cache do
context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do
let(:user) { create(:user) }
before do
......@@ -316,22 +316,18 @@ RSpec.describe Issues::CreateService do
context 'when too many requests are sent by one user' do
it 'raises an error' do
freeze_time do
expect do
subject
end.to raise_error(RateLimitedService::RateLimitedError)
end
end
it 'creates 1 issue' do
freeze_time do
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
end
end
context 'when limit is higher than counf of issues being created' do
before do
......@@ -339,12 +335,10 @@ RSpec.describe Issues::CreateService do
end
it 'creates 2 issues' do
freeze_time do
expect { subject }.to change { Issue.count }.by(2)
end
end
end
end
context 'after_save callback to store_mentions' do
context 'when mentionable attributes change' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment