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 ...@@ -493,12 +493,12 @@ RSpec.describe Groups::EpicsController do
end end
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 before do
stub_application_setting(issues_create_limit: 5) stub_application_setting(issues_create_limit: 5)
end 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' } } } 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' } } post :create, params: { group_id: group, epic: { title: 'new epic', description: 'description' } }
......
...@@ -1408,7 +1408,7 @@ RSpec.describe Projects::IssuesController do ...@@ -1408,7 +1408,7 @@ RSpec.describe Projects::IssuesController do
end end
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 before do
stub_application_setting(issues_create_limit: 5) stub_application_setting(issues_create_limit: 5)
end end
......
...@@ -259,7 +259,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do ...@@ -259,7 +259,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end end
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) } let(:receiver) { Gitlab::Email::Receiver.new(email_raw) }
subject { 2.times { receiver.execute } } subject { 2.times { receiver.execute } }
...@@ -271,18 +271,14 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do ...@@ -271,18 +271,14 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
context 'when too many requests are sent by one user' do context 'when too many requests are sent by one user' do
it 'raises an error' do it 'raises an error' do
freeze_time do expect { subject }.to raise_error(RateLimitedService::RateLimitedError)
expect { subject }.to raise_error(RateLimitedService::RateLimitedError)
end
end end
it 'creates 1 issue' do it 'creates 1 issue' do
freeze_time do expect do
expect do subject
subject rescue RateLimitedService::RateLimitedError
rescue RateLimitedService::RateLimitedError end.to change { Issue.count }.by(1)
end.to change { Issue.count }.by(1)
end
end end
context 'when requests are sent by different users' do context 'when requests are sent by different users' do
...@@ -295,9 +291,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do ...@@ -295,9 +291,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end end
it 'creates 2 issues' do it 'creates 2 issues' do
freeze_time do expect { subject }.to change { Issue.count }.by(2)
expect { subject }.to change { Issue.count }.by(2)
end
end end
end end
end end
...@@ -308,9 +302,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do ...@@ -308,9 +302,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end end
it 'creates 2 issues' do it 'creates 2 issues' do
freeze_time do expect { subject }.to change { Issue.count }.by(2)
expect { subject }.to change { Issue.count }.by(2)
end
end end
end end
end end
......
...@@ -302,7 +302,7 @@ RSpec.describe Issues::CreateService do ...@@ -302,7 +302,7 @@ RSpec.describe Issues::CreateService do
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
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(:user) { create(:user) } let(:user) { create(:user) }
before do before do
...@@ -316,20 +316,16 @@ RSpec.describe Issues::CreateService do ...@@ -316,20 +316,16 @@ RSpec.describe Issues::CreateService do
context 'when too many requests are sent by one user' do context 'when too many requests are sent by one user' do
it 'raises an error' do it 'raises an error' do
freeze_time do expect do
expect do subject
subject end.to raise_error(RateLimitedService::RateLimitedError)
end.to raise_error(RateLimitedService::RateLimitedError)
end
end end
it 'creates 1 issue' do it 'creates 1 issue' do
freeze_time do expect do
expect do subject
subject rescue RateLimitedService::RateLimitedError
rescue RateLimitedService::RateLimitedError end.to change { Issue.count }.by(1)
end.to change { Issue.count }.by(1)
end
end end
end end
...@@ -339,9 +335,7 @@ RSpec.describe Issues::CreateService do ...@@ -339,9 +335,7 @@ RSpec.describe Issues::CreateService do
end end
it 'creates 2 issues' do it 'creates 2 issues' do
freeze_time do expect { subject }.to change { Issue.count }.by(2)
expect { subject }.to change { Issue.count }.by(2)
end
end end
end 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