Commit 92802e51 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'blackst0ne-replace-sidekiq-inline-with-perform-enqueued-jobs' into 'master'

Replace 'Sidekiq::Testing.inline!' with 'perform_enqueued_jobs'

Closes #22991

See merge request gitlab-org/gitlab-ce!20768
parents 771e9374 4691fd02
---
title: Replace 'Sidekiq::Testing.inline!' with 'perform_enqueued_jobs'
merge_request: 20768
author: "@blackst0ne"
type: other
...@@ -7,7 +7,7 @@ describe 'GPG signed commits', :js do ...@@ -7,7 +7,7 @@ describe 'GPG signed commits', :js do
user = create :user, email: 'unrelated.user@example.org' user = create :user, email: 'unrelated.user@example.org'
project.add_maintainer(user) project.add_maintainer(user)
Sidekiq::Testing.inline! do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end end
...@@ -21,7 +21,7 @@ describe 'GPG signed commits', :js do ...@@ -21,7 +21,7 @@ describe 'GPG signed commits', :js do
end end
# user changes his email which makes the gpg key verified # user changes his email which makes the gpg key verified
Sidekiq::Testing.inline! do perform_enqueued_jobs do
user.skip_reconfirmation! user.skip_reconfirmation!
user.update!(email: GpgHelpers::User1.emails.first) user.update!(email: GpgHelpers::User1.emails.first)
end end
...@@ -48,7 +48,7 @@ describe 'GPG signed commits', :js do ...@@ -48,7 +48,7 @@ describe 'GPG signed commits', :js do
end end
# user adds the gpg key which makes the signature valid # user adds the gpg key which makes the signature valid
Sidekiq::Testing.inline! do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end end
...@@ -66,7 +66,7 @@ describe 'GPG signed commits', :js do ...@@ -66,7 +66,7 @@ describe 'GPG signed commits', :js do
end end
let(:user_1_key) do let(:user_1_key) do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user_1 create :gpg_key, key: GpgHelpers::User1.public_key, user: user_1
end end
end end
...@@ -79,7 +79,7 @@ describe 'GPG signed commits', :js do ...@@ -79,7 +79,7 @@ describe 'GPG signed commits', :js do
end end
let(:user_2_key) do let(:user_2_key) do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User2.public_key, user: user_2 create :gpg_key, key: GpgHelpers::User2.public_key, user: user_2
end end
end end
......
...@@ -65,7 +65,7 @@ describe Gitlab::HashedStorage::Migrator do ...@@ -65,7 +65,7 @@ describe Gitlab::HashedStorage::Migrator do
end end
it 'migrate project' do it 'migrate project' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
subject.migrate(project) subject.migrate(project)
end end
......
...@@ -31,7 +31,7 @@ describe ScheduleSetConfidentialNoteEventsOnServices, :migration, :sidekiq do ...@@ -31,7 +31,7 @@ describe ScheduleSetConfidentialNoteEventsOnServices, :migration, :sidekiq do
end end
it 'correctly processes services' do it 'correctly processes services' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(services_table.where(confidential_note_events: nil).count).to eq 4 expect(services_table.where(confidential_note_events: nil).count).to eq 4
expect(services_table.where(confidential_note_events: true).count).to eq 1 expect(services_table.where(confidential_note_events: true).count).to eq 1
......
...@@ -44,7 +44,7 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do ...@@ -44,7 +44,7 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
end end
it 'schedules background migrations' do it 'schedules background migrations' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(jobs.where(stage_id: nil).count).to eq 5 expect(jobs.where(stage_id: nil).count).to eq 5
migrate! migrate!
......
...@@ -34,7 +34,7 @@ describe MigrateStagesStatuses, :sidekiq, :migration do ...@@ -34,7 +34,7 @@ describe MigrateStagesStatuses, :sidekiq, :migration do
end end
it 'correctly migrates stages statuses' do it 'correctly migrates stages statuses' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(stages.where(status: nil).count).to eq 3 expect(stages.where(status: nil).count).to eq 3
migrate! migrate!
......
...@@ -38,7 +38,7 @@ describe NormalizeLdapExternUids, :migration, :sidekiq do ...@@ -38,7 +38,7 @@ describe NormalizeLdapExternUids, :migration, :sidekiq do
end end
it 'migrates the LDAP identities' do it 'migrates the LDAP identities' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
migrate! migrate!
identities.where(id: 1..4).each do |identity| identities.where(id: 1..4).each do |identity|
expect(identity.extern_uid).to eq("uid=foo #{identity.id},ou=people,dc=example,dc=com") expect(identity.extern_uid).to eq("uid=foo #{identity.id},ou=people,dc=example,dc=com")
...@@ -47,7 +47,7 @@ describe NormalizeLdapExternUids, :migration, :sidekiq do ...@@ -47,7 +47,7 @@ describe NormalizeLdapExternUids, :migration, :sidekiq do
end end
it 'does not modify non-LDAP identities' do it 'does not modify non-LDAP identities' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
migrate! migrate!
identity = identities.last identity = identities.last
expect(identity.extern_uid).to eq(" uid = foo 5, ou = People, dc = example, dc = com ") expect(identity.extern_uid).to eq(" uid = foo 5, ou = People, dc = example, dc = com ")
......
...@@ -20,7 +20,7 @@ describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do ...@@ -20,7 +20,7 @@ describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do
end end
it 'schedules background migrations' do it 'schedules background migrations' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(GpgKeySubkey.count).to eq(0) expect(GpgKeySubkey.count).to eq(0)
migrate! migrate!
......
...@@ -33,7 +33,7 @@ describe ScheduleMergeRequestDiffMigrations, :migration, :sidekiq do ...@@ -33,7 +33,7 @@ describe ScheduleMergeRequestDiffMigrations, :migration, :sidekiq do
end end
it 'schedules background migrations' do it 'schedules background migrations' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
non_empty = 'st_commits IS NOT NULL OR st_diffs IS NOT NULL' non_empty = 'st_commits IS NOT NULL OR st_diffs IS NOT NULL'
expect(merge_request_diffs.where(non_empty).count).to eq 3 expect(merge_request_diffs.where(non_empty).count).to eq 3
......
...@@ -33,7 +33,7 @@ describe ScheduleMergeRequestDiffMigrationsTakeTwo, :migration, :sidekiq do ...@@ -33,7 +33,7 @@ describe ScheduleMergeRequestDiffMigrationsTakeTwo, :migration, :sidekiq do
end end
it 'migrates the data' do it 'migrates the data' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
non_empty = 'st_commits IS NOT NULL OR st_diffs IS NOT NULL' non_empty = 'st_commits IS NOT NULL OR st_diffs IS NOT NULL'
expect(merge_request_diffs.where(non_empty).count).to eq 3 expect(merge_request_diffs.where(non_empty).count).to eq 3
......
...@@ -53,7 +53,7 @@ describe ScheduleMergeRequestLatestMergeRequestDiffIdMigrations, :migration, :si ...@@ -53,7 +53,7 @@ describe ScheduleMergeRequestLatestMergeRequestDiffIdMigrations, :migration, :si
end end
it 'schedules background migrations' do it 'schedules background migrations' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(merge_requests_table.where(latest_merge_request_diff_id: nil).count).to eq 3 expect(merge_requests_table.where(latest_merge_request_diff_id: nil).count).to eq 3
migrate! migrate!
......
...@@ -31,7 +31,7 @@ describe ScheduleSetConfidentialNoteEventsOnWebhooks, :migration, :sidekiq do ...@@ -31,7 +31,7 @@ describe ScheduleSetConfidentialNoteEventsOnWebhooks, :migration, :sidekiq do
end end
it 'correctly processes web hooks' do it 'correctly processes web hooks' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect(web_hooks_table.where(confidential_note_events: nil).count).to eq 4 expect(web_hooks_table.where(confidential_note_events: nil).count).to eq 4
expect(web_hooks_table.where(confidential_note_events: true).count).to eq 1 expect(web_hooks_table.where(confidential_note_events: true).count).to eq 1
......
...@@ -179,7 +179,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do ...@@ -179,7 +179,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end end
it 'migrates data to object storage' do it 'migrates data to object storage' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
subject subject
build_trace_chunk.reload build_trace_chunk.reload
...@@ -201,7 +201,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do ...@@ -201,7 +201,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end end
it 'does not migrate data to object storage' do it 'does not migrate data to object storage' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
data_store = build_trace_chunk.data_store data_store = build_trace_chunk.data_store
subject subject
......
...@@ -22,7 +22,7 @@ describe SpamLog do ...@@ -22,7 +22,7 @@ describe SpamLog do
spam_log = build(:spam_log) spam_log = build(:spam_log)
user = spam_log.user user = spam_log.user
Sidekiq::Testing.inline! do perform_enqueued_jobs do
spam_log.remove_user(deleted_by: admin) spam_log.remove_user(deleted_by: admin)
end end
......
...@@ -102,7 +102,7 @@ describe API::ProjectImport do ...@@ -102,7 +102,7 @@ describe API::ProjectImport do
it 'correctly overrides params during the import' do it 'correctly overrides params during the import' do
override_params = { 'description' => 'Hello world' } override_params = { 'description' => 'Hello world' }
Sidekiq::Testing.inline! do perform_enqueued_jobs do
post api('/projects/import', user), post api('/projects/import', user),
path: 'test-import', path: 'test-import',
file: fixture_file_upload(file), file: fixture_file_upload(file),
......
...@@ -1067,7 +1067,7 @@ describe API::Users do ...@@ -1067,7 +1067,7 @@ describe API::Users do
end end
it "deletes user" do it "deletes user" do
Sidekiq::Testing.inline! { delete api("/users/#{user.id}", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(204)
expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
...@@ -1079,30 +1079,30 @@ describe API::Users do ...@@ -1079,30 +1079,30 @@ describe API::Users do
end end
it "does not delete for unauthenticated user" do it "does not delete for unauthenticated user" do
Sidekiq::Testing.inline! { delete api("/users/#{user.id}") } perform_enqueued_jobs { delete api("/users/#{user.id}") }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
it "is not available for non admin users" do it "is not available for non admin users" do
Sidekiq::Testing.inline! { delete api("/users/#{user.id}", user) } perform_enqueued_jobs { delete api("/users/#{user.id}", user) }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
it "returns 404 for non-existing user" do it "returns 404 for non-existing user" do
Sidekiq::Testing.inline! { delete api("/users/999999", admin) } perform_enqueued_jobs { delete api("/users/999999", admin) }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
Sidekiq::Testing.inline! { delete api("/users/ASDF", admin) } perform_enqueued_jobs { delete api("/users/ASDF", admin) }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
context "hard delete disabled" do context "hard delete disabled" do
it "moves contributions to the ghost user" do it "moves contributions to the ghost user" do
Sidekiq::Testing.inline! { delete api("/users/#{user.id}", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(204)
expect(issue.reload).to be_persisted expect(issue.reload).to be_persisted
...@@ -1112,7 +1112,7 @@ describe API::Users do ...@@ -1112,7 +1112,7 @@ describe API::Users do
context "hard delete enabled" do context "hard delete enabled" do
it "removes contributions" do it "removes contributions" do
Sidekiq::Testing.inline! { delete api("/users/#{user.id}?hard_delete=true", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}?hard_delete=true", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(204)
expect(Issue.exists?(issue.id)).to be_falsy expect(Issue.exists?(issue.id)).to be_falsy
......
...@@ -49,7 +49,7 @@ describe Groups::DestroyService do ...@@ -49,7 +49,7 @@ describe Groups::DestroyService do
context 'Sidekiq inline' do context 'Sidekiq inline' do
before do before do
# Run sidekiq immediately to check that renamed dir will be removed # Run sidekiq immediately to check that renamed dir will be removed
Sidekiq::Testing.inline! { destroy_group(group, user, async) } perform_enqueued_jobs { destroy_group(group, user, async) }
end end
it 'verifies that paths have been deleted' do it 'verifies that paths have been deleted' do
......
...@@ -28,7 +28,7 @@ describe Projects::CreateFromTemplateService do ...@@ -28,7 +28,7 @@ describe Projects::CreateFromTemplateService do
context 'the result project' do context 'the result project' do
before do before do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
@project = subject.execute @project = subject.execute
end end
......
...@@ -45,18 +45,18 @@ describe Projects::DestroyService do ...@@ -45,18 +45,18 @@ describe Projects::DestroyService do
shared_examples 'handles errors thrown during async destroy' do |error_message| shared_examples 'handles errors thrown during async destroy' do |error_message|
it 'does not allow the error to bubble up' do it 'does not allow the error to bubble up' do
expect do expect do
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
end.not_to raise_error end.not_to raise_error
end end
it 'unmarks the project as "pending deletion"' do it 'unmarks the project as "pending deletion"' do
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
expect(project.reload.pending_delete).to be(false) expect(project.reload.pending_delete).to be(false)
end end
it 'stores an error message in `projects.delete_error`' do it 'stores an error message in `projects.delete_error`' do
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
expect(project.reload.delete_error).to be_present expect(project.reload.delete_error).to be_present
expect(project.delete_error).to include(error_message) expect(project.delete_error).to include(error_message)
...@@ -66,7 +66,7 @@ describe Projects::DestroyService do ...@@ -66,7 +66,7 @@ describe Projects::DestroyService do
context 'Sidekiq inline' do context 'Sidekiq inline' do
before do before do
# Run sidekiq immediatly to check that renamed repository will be removed # Run sidekiq immediatly to check that renamed repository will be removed
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
end end
context 'when has remote mirrors' do context 'when has remote mirrors' do
...@@ -110,7 +110,7 @@ describe Projects::DestroyService do ...@@ -110,7 +110,7 @@ describe Projects::DestroyService do
end end
it 'keeps project team intact upon an error' do it 'keeps project team intact upon an error' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
begin begin
destroy_project(project, user, {}) destroy_project(project, user, {})
rescue ::Redis::CannotConnectError rescue ::Redis::CannotConnectError
...@@ -128,7 +128,7 @@ describe Projects::DestroyService do ...@@ -128,7 +128,7 @@ describe Projects::DestroyService do
before do before do
project.project_feature.update_attribute("issues_access_level", ProjectFeature::PRIVATE) project.project_feature.update_attribute("issues_access_level", ProjectFeature::PRIVATE)
# Run sidekiq immediately to check that renamed repository will be removed # Run sidekiq immediately to check that renamed repository will be removed
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
end end
it_behaves_like 'deleting the project' it_behaves_like 'deleting the project'
...@@ -172,7 +172,7 @@ describe Projects::DestroyService do ...@@ -172,7 +172,7 @@ describe Projects::DestroyService do
it 'allows error to bubble up and rolls back project deletion' do it 'allows error to bubble up and rolls back project deletion' do
expect do expect do
Sidekiq::Testing.inline! { destroy_project(project, user, {}) } perform_enqueued_jobs { destroy_project(project, user, {}) }
end.to raise_error(Exception, 'Other error message') end.to raise_error(Exception, 'Other error message')
expect(project.reload.pending_delete).to be(false) expect(project.reload.pending_delete).to be(false)
......
...@@ -35,7 +35,7 @@ describe Projects::HousekeepingService do ...@@ -35,7 +35,7 @@ describe Projects::HousekeepingService do
allow(subject).to receive(:gc_period).and_return(1) allow(subject).to receive(:gc_period).and_return(1)
project.increment_pushes_since_gc project.increment_pushes_since_gc
Sidekiq::Testing.inline! do perform_enqueued_jobs do
expect { subject.execute }.to change { project.pushes_since_gc }.to(0) expect { subject.execute }.to change { project.pushes_since_gc }.to(0)
end end
end end
......
...@@ -173,7 +173,7 @@ describe Users::DestroyService do ...@@ -173,7 +173,7 @@ describe Users::DestroyService do
describe "user personal's repository removal" do describe "user personal's repository removal" do
before do before do
Sidekiq::Testing.inline! { service.execute(user) } perform_enqueued_jobs { service.execute(user) }
end end
context 'legacy storage' do context 'legacy storage' do
......
...@@ -13,7 +13,7 @@ describe StorageMigratorWorker do ...@@ -13,7 +13,7 @@ describe StorageMigratorWorker do
end end
it 'migrates projects in the specified range' do it 'migrates projects in the specified range' do
Sidekiq::Testing.inline! do perform_enqueued_jobs do
worker.perform(ids.min, ids.max) worker.perform(ids.min, ids.max)
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