Commit 6c2e8813 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'refactor/ce_stubbed_worker' into 'master'

Refactor subbed_worker calls

Closes #58484

See merge request gitlab-org/gitlab-ce!26708
parents a7cf6135 4e5a9838
...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20181219145520_migrate_cluster_co ...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20181219145520_migrate_cluster_co
describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queue' do context 'when there are jobs in the queue' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'gcp_cluster:cluster_platform_configure').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_platform_configure').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:cluster_configure').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_configure').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -19,12 +20,12 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do ...@@ -19,12 +20,12 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do
it 'does not affect other queues under the same namespace' do it 'does not affect other queues under the same namespace' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'gcp_cluster:cluster_install_app').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_install_app').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:cluster_provision').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_provision').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:cluster_wait_for_app_installation').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_wait_for_app_installation').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:wait_for_cluster_creation').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:wait_for_cluster_creation').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:cluster_wait_for_ingress_ip_address').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_wait_for_ingress_ip_address').perform_async('Something', [1])
stubbed_worker(queue: 'gcp_cluster:cluster_project_configure').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_project_configure').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -39,7 +40,7 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do ...@@ -39,7 +40,7 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do
it 'correctly migrates queue when migrating down' do it 'correctly migrates queue when migrating down' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'gcp_cluster:cluster_configure').perform_async('Something', [1]) stub_worker(queue: 'gcp_cluster:cluster_configure').perform_async('Something', [1])
described_class.new.down described_class.new.down
...@@ -58,11 +59,4 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do ...@@ -58,11 +59,4 @@ describe MigrateClusterConfigureWorkerSidekiqQueue, :sidekiq, :redis do
expect { described_class.new.down }.not_to raise_error expect { described_class.new.down }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180306074045_migrate_create_tra ...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180306074045_migrate_create_tra
describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queues' do context 'when there are jobs in the queues' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_default:create_trace_artifact').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:create_trace_artifact').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_background:archive_trace').perform_async('Something', [1]) stub_worker(queue: 'pipeline_background:archive_trace').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -19,11 +20,11 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do ...@@ -19,11 +20,11 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do
it 'does not affect other queues under the same namespace' do it 'does not affect other queues under the same namespace' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_default:build_coverage').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:build_coverage').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:build_trace_sections').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:build_trace_sections').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:pipeline_metrics').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:pipeline_metrics').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:pipeline_notification').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:pipeline_notification').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:update_head_pipeline_for_merge_request').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:update_head_pipeline_for_merge_request').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -37,7 +38,7 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do ...@@ -37,7 +38,7 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do
it 'correctly migrates queue when migrating down' do it 'correctly migrates queue when migrating down' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_background:archive_trace').perform_async('Something', [1]) stub_worker(queue: 'pipeline_background:archive_trace').perform_async('Something', [1])
described_class.new.down described_class.new.down
...@@ -56,11 +57,4 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do ...@@ -56,11 +57,4 @@ describe MigrateCreateTraceArtifactSidekiqQueue, :sidekiq, :redis do
expect { described_class.new.down }.not_to raise_error expect { described_class.new.down }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180603190921_migrate_object_sto ...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180603190921_migrate_object_sto
describe MigrateObjectStorageUploadSidekiqQueue, :sidekiq, :redis do describe MigrateObjectStorageUploadSidekiqQueue, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queue' do context 'when there are jobs in the queue' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'object_storage_upload').perform_async('Something', [1]) stub_worker(queue: 'object_storage_upload').perform_async('Something', [1])
stubbed_worker(queue: 'object_storage:object_storage_background_move').perform_async('Something', [1]) stub_worker(queue: 'object_storage:object_storage_background_move').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -23,11 +24,4 @@ describe MigrateObjectStorageUploadSidekiqQueue, :sidekiq, :redis do ...@@ -23,11 +24,4 @@ describe MigrateObjectStorageUploadSidekiqQueue, :sidekiq, :redis do
expect { described_class.new.up }.not_to raise_error expect { described_class.new.up }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20170822101017_migrate_pipeline_s ...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20170822101017_migrate_pipeline_s
describe MigratePipelineSidekiqQueues, :sidekiq, :redis do describe MigratePipelineSidekiqQueues, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queues' do context 'when there are jobs in the queues' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: :pipeline).perform_async('Something', [1]) stub_worker(queue: :pipeline).perform_async('Something', [1])
stubbed_worker(queue: :build).perform_async('Something', [1]) stub_worker(queue: :build).perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -20,10 +21,10 @@ describe MigratePipelineSidekiqQueues, :sidekiq, :redis do ...@@ -20,10 +21,10 @@ describe MigratePipelineSidekiqQueues, :sidekiq, :redis do
it 'correctly migrates queue when migrating down' do it 'correctly migrates queue when migrating down' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: :pipeline_default).perform_async('Class', [1]) stub_worker(queue: :pipeline_default).perform_async('Class', [1])
stubbed_worker(queue: :pipeline_processing).perform_async('Class', [2]) stub_worker(queue: :pipeline_processing).perform_async('Class', [2])
stubbed_worker(queue: :pipeline_hooks).perform_async('Class', [3]) stub_worker(queue: :pipeline_hooks).perform_async('Class', [3])
stubbed_worker(queue: :pipeline_cache).perform_async('Class', [4]) stub_worker(queue: :pipeline_cache).perform_async('Class', [4])
described_class.new.down described_class.new.down
...@@ -45,11 +46,4 @@ describe MigratePipelineSidekiqQueues, :sidekiq, :redis do ...@@ -45,11 +46,4 @@ describe MigratePipelineSidekiqQueues, :sidekiq, :redis do
expect { described_class.new.down }.not_to raise_error expect { described_class.new.down }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
...@@ -3,11 +3,12 @@ require Rails.root.join('db', 'post_migrate', '20190124200344_migrate_storage_mi ...@@ -3,11 +3,12 @@ require Rails.root.join('db', 'post_migrate', '20190124200344_migrate_storage_mi
describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queues' do context 'when there are jobs in the queues' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: :storage_migrator).perform_async(1, 5) stub_worker(queue: :storage_migrator).perform_async(1, 5)
described_class.new.up described_class.new.up
...@@ -18,7 +19,7 @@ describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do ...@@ -18,7 +19,7 @@ describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do
it 'correctly migrates queue when migrating down' do it 'correctly migrates queue when migrating down' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: :'hashed_storage:hashed_storage_migrator').perform_async(1, 5) stub_worker(queue: :'hashed_storage:hashed_storage_migrator').perform_async(1, 5)
described_class.new.down described_class.new.down
...@@ -37,11 +38,4 @@ describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do ...@@ -37,11 +38,4 @@ describe MigrateStorageMigratorSidekiqQueue, :sidekiq, :redis do
expect { described_class.new.down }.not_to raise_error expect { described_class.new.down }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180307012445_migrate_update_hea ...@@ -3,12 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20180307012445_migrate_update_hea
describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis do describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis do
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
include StubWorker
context 'when there are jobs in the queues' do context 'when there are jobs in the queues' do
it 'correctly migrates queue when migrating up' do it 'correctly migrates queue when migrating up' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_default:update_head_pipeline_for_merge_request').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:update_head_pipeline_for_merge_request').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_processing:update_head_pipeline_for_merge_request').perform_async('Something', [1]) stub_worker(queue: 'pipeline_processing:update_head_pipeline_for_merge_request').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -19,10 +20,10 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis ...@@ -19,10 +20,10 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis
it 'does not affect other queues under the same namespace' do it 'does not affect other queues under the same namespace' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_default:build_coverage').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:build_coverage').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:build_trace_sections').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:build_trace_sections').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:pipeline_metrics').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:pipeline_metrics').perform_async('Something', [1])
stubbed_worker(queue: 'pipeline_default:pipeline_notification').perform_async('Something', [1]) stub_worker(queue: 'pipeline_default:pipeline_notification').perform_async('Something', [1])
described_class.new.up described_class.new.up
...@@ -35,7 +36,7 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis ...@@ -35,7 +36,7 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis
it 'correctly migrates queue when migrating down' do it 'correctly migrates queue when migrating down' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
stubbed_worker(queue: 'pipeline_processing:update_head_pipeline_for_merge_request').perform_async('Something', [1]) stub_worker(queue: 'pipeline_processing:update_head_pipeline_for_merge_request').perform_async('Something', [1])
described_class.new.down described_class.new.down
...@@ -54,11 +55,4 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis ...@@ -54,11 +55,4 @@ describe MigrateUpdateHeadPipelineForMergeRequestSidekiqQueue, :sidekiq, :redis
expect { described_class.new.down }.not_to raise_error expect { described_class.new.down }.not_to raise_error
end end
end end
def stubbed_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
end
end
end end
# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb
module StubWorker
def stub_worker(queue:)
Class.new do
include Sidekiq::Worker
sidekiq_options queue: queue
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