Commit d351f344 authored by Alper Akgun's avatar Alper Akgun

Merge branch '345422-fix-flaky-tests-due-to-rate-limiter-change' into 'master'

Fix flaky specs due to rate limiter change

See merge request gitlab-org/gitlab!74264
parents e76de70e d0b32815
......@@ -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,18 +271,14 @@ 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
expect { subject }.to raise_error(RateLimitedService::RateLimitedError)
end
it 'creates 1 issue' do
freeze_time do
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
context 'when requests are sent by different users' do
......@@ -295,9 +291,7 @@ 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
expect { subject }.to change { Issue.count }.by(2)
end
end
end
......@@ -308,9 +302,7 @@ 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
expect { subject }.to change { Issue.count }.by(2)
end
end
end
......
......@@ -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,20 +316,16 @@ 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
expect do
subject
end.to raise_error(RateLimitedService::RateLimitedError)
end
it 'creates 1 issue' do
freeze_time do
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
expect do
subject
rescue RateLimitedService::RateLimitedError
end.to change { Issue.count }.by(1)
end
end
......@@ -339,9 +335,7 @@ RSpec.describe Issues::CreateService do
end
it 'creates 2 issues' do
freeze_time do
expect { subject }.to change { Issue.count }.by(2)
end
expect { subject }.to change { Issue.count }.by(2)
end
end
end
......
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