Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/bulk_imports/export_request_worker_spec.rb18
-rw-r--r--spec/workers/ci/unlock_pipelines_in_queue_worker_spec.rb9
-rw-r--r--spec/workers/click_house/event_authors_consistency_cron_worker_spec.rb104
-rw-r--r--spec/workers/click_house/events_sync_worker_spec.rb174
-rw-r--r--spec/workers/concerns/gitlab/github_import/object_importer_spec.rb27
-rw-r--r--spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb11
-rw-r--r--spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb195
-rw-r--r--spec/workers/emails_on_push_worker_spec.rb4
-rw-r--r--spec/workers/every_sidekiq_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb15
-rw-r--r--spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb65
-rw-r--r--spec/workers/gitlab/github_import/replay_events_worker_spec.rb32
-rw-r--r--spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb5
-rw-r--r--spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb7
-rw-r--r--spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb4
-rw-r--r--spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb6
-rw-r--r--spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb24
-rw-r--r--spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb7
-rw-r--r--spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb10
-rw-r--r--spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb7
-rw-r--r--spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb4
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb6
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb6
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb7
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb6
-rw-r--r--spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb4
-rw-r--r--spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb8
-rw-r--r--spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb2
-rw-r--r--spec/workers/jira_connect/sync_project_worker_spec.rb4
-rw-r--r--spec/workers/new_issue_worker_spec.rb8
-rw-r--r--spec/workers/releases/publish_event_worker_spec.rb45
31 files changed, 386 insertions, 440 deletions
diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb
index 2cc6348bb27..25adaef28fd 100644
--- a/spec/workers/bulk_imports/export_request_worker_spec.rb
+++ b/spec/workers/bulk_imports/export_request_worker_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do
context 'when something goes wrong during source id fetch' do
let(:entity_source_id) { 'invalid' }
- it 'logs the error & requests relations export using full path url' do
+ it 'logs the exception as a warning & requests relations export using full path url' do
allow(BulkImports::EntityWorker).to receive(:perform_async)
expect_next_instance_of(BulkImports::Clients::HTTP) do |client|
@@ -74,7 +74,7 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do
expect_next_instance_of(BulkImports::Logger) do |logger|
expect(logger).to receive(:with_entity).with(entity).and_call_original
- expect(logger).to receive(:error).with(
+ expect(logger).to receive(:warn).with(
a_hash_including(
'exception.backtrace' => anything,
'exception.class' => 'NoMethodError',
@@ -123,20 +123,6 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do
described_class.new.perform(entity.id)
end
-
- context 'when bulk_imports_batched_import_export feature flag is disabled' do
- it 'requests relation export without batched param' do
- stub_feature_flags(bulk_imports_batched_import_export: false)
-
- expected_url = "/projects/#{entity.source_xid}/export_relations"
-
- expect_next_instance_of(BulkImports::Clients::HTTP) do |client|
- expect(client).to receive(:post).with(expected_url)
- end
-
- described_class.new.perform(entity.id)
- end
- end
end
end
diff --git a/spec/workers/ci/unlock_pipelines_in_queue_worker_spec.rb b/spec/workers/ci/unlock_pipelines_in_queue_worker_spec.rb
index ca1d234eb5b..d48eed4ae90 100644
--- a/spec/workers/ci/unlock_pipelines_in_queue_worker_spec.rb
+++ b/spec/workers/ci/unlock_pipelines_in_queue_worker_spec.rb
@@ -101,6 +101,7 @@ RSpec.describe Ci::UnlockPipelinesInQueueWorker, :unlock_pipelines, :clean_gitla
before do
stub_feature_flags(
+ ci_unlock_pipelines_extra_low: false,
ci_unlock_pipelines: false,
ci_unlock_pipelines_medium: false,
ci_unlock_pipelines_high: false
@@ -109,6 +110,14 @@ RSpec.describe Ci::UnlockPipelinesInQueueWorker, :unlock_pipelines, :clean_gitla
it { is_expected.to eq(0) }
+ context 'when ci_unlock_pipelines_extra_low flag is enabled' do
+ before do
+ stub_feature_flags(ci_unlock_pipelines_extra_low: true)
+ end
+
+ it { is_expected.to eq(described_class::MAX_RUNNING_EXTRA_LOW) }
+ end
+
context 'when ci_unlock_pipelines flag is enabled' do
before do
stub_feature_flags(ci_unlock_pipelines: true)
diff --git a/spec/workers/click_house/event_authors_consistency_cron_worker_spec.rb b/spec/workers/click_house/event_authors_consistency_cron_worker_spec.rb
new file mode 100644
index 00000000000..d4fa35b9b82
--- /dev/null
+++ b/spec/workers/click_house/event_authors_consistency_cron_worker_spec.rb
@@ -0,0 +1,104 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ClickHouse::EventAuthorsConsistencyCronWorker, feature_category: :value_stream_management do
+ let(:worker) { described_class.new }
+
+ context 'when ClickHouse is disabled' do
+ it 'does nothing' do
+ allow(ClickHouse::Client).to receive(:database_configured?).and_return(false)
+
+ expect(worker).not_to receive(:log_extra_metadata_on_done)
+
+ worker.perform
+ end
+ end
+
+ context 'when the event_sync_worker_for_click_house feature flag is off' do
+ it 'does nothing' do
+ allow(ClickHouse::Client).to receive(:database_configured?).and_return(true)
+ stub_feature_flags(event_sync_worker_for_click_house: false)
+
+ expect(worker).not_to receive(:log_extra_metadata_on_done)
+
+ worker.perform
+ end
+ end
+
+ context 'when ClickHouse is available', :click_house do
+ let_it_be(:connection) { ClickHouse::Connection.new(:main) }
+ let_it_be_with_reload(:user1) { create(:user) }
+ let_it_be_with_reload(:user2) { create(:user) }
+
+ let(:leftover_author_ids) { connection.select('SELECT DISTINCT author_id FROM events FINAL').pluck('author_id') }
+ let(:deleted_user_id1) { user2.id + 1 }
+ let(:deleted_user_id2) { user2.id + 2 }
+
+ before do
+ insert_query = <<~SQL
+ INSERT INTO events (id, author_id) VALUES
+ (1, #{user1.id}),
+ (2, #{user2.id}),
+ (3, #{deleted_user_id1}),
+ (4, #{deleted_user_id1}),
+ (5, #{deleted_user_id2})
+ SQL
+
+ connection.execute(insert_query)
+ end
+
+ it 'cleans up all inconsistent records in ClickHouse' do
+ worker.perform
+
+ expect(leftover_author_ids).to contain_exactly(user1.id, user2.id)
+
+ # the next job starts from the beginning of the table
+ expect(ClickHouse::SyncCursor.cursor_for(:event_authors_consistency_check)).to eq(0)
+ end
+
+ context 'when the previous job was not finished' do
+ it 'continues the processing from the cursor' do
+ ClickHouse::SyncCursor.update_cursor_for(:event_authors_consistency_check, deleted_user_id1)
+
+ worker.perform
+
+ # the previous records should remain
+ expect(leftover_author_ids).to contain_exactly(user1.id, user2.id)
+ end
+ end
+
+ context 'when processing stops due to the record clean up limit' do
+ it 'stores the last processed id value' do
+ User.where(id: [user1.id, user2.id]).delete_all
+
+ stub_const("#{described_class}::MAX_AUTHOR_DELETIONS", 2)
+ stub_const("#{described_class}::POSTGRESQL_BATCH_SIZE", 1)
+
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
+ { status: :deletion_limit_reached, deletions: 2 })
+
+ worker.perform
+
+ expect(leftover_author_ids).to contain_exactly(deleted_user_id1, deleted_user_id2)
+ expect(ClickHouse::SyncCursor.cursor_for(:event_authors_consistency_check)).to eq(user2.id)
+ end
+ end
+
+ context 'when time limit is reached' do
+ it 'stops the processing earlier' do
+ stub_const("#{described_class}::POSTGRESQL_BATCH_SIZE", 1)
+
+ # stop at the third author_id
+ allow_next_instance_of(Analytics::CycleAnalytics::RuntimeLimiter) do |runtime_limiter|
+ allow(runtime_limiter).to receive(:over_time?).and_return(false, false, true)
+ end
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:result, { status: :over_time, deletions: 1 })
+
+ worker.perform
+
+ expect(leftover_author_ids).to contain_exactly(user1.id, user2.id, deleted_user_id2)
+ end
+ end
+ end
+end
diff --git a/spec/workers/click_house/events_sync_worker_spec.rb b/spec/workers/click_house/events_sync_worker_spec.rb
index 9662f26115a..dc3dea24e37 100644
--- a/spec/workers/click_house/events_sync_worker_spec.rb
+++ b/spec/workers/click_house/events_sync_worker_spec.rb
@@ -11,176 +11,20 @@ RSpec.describe ClickHouse::EventsSyncWorker, feature_category: :value_stream_man
)
end
- it_behaves_like 'an idempotent worker' do
- context 'when the event_sync_worker_for_click_house feature flag is on', :click_house do
- before do
- stub_feature_flags(event_sync_worker_for_click_house: true)
+ context 'when worker is enqueued' do
+ it 'calls ::ClickHouse::SyncStrategies::EventSyncStrategy with correct args' do
+ expect_next_instance_of(::ClickHouse::SyncStrategies::EventSyncStrategy) do |instance|
+ expect(instance).to receive(:execute)
end
- context 'when there is nothing to sync' do
- it 'adds metadata for the worker' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 0, reached_end_of_table: true })
-
- worker.perform
-
- events = ClickHouse::Client.select('SELECT * FROM events', :main)
- expect(events).to be_empty
- end
- end
-
- context 'when syncing records' do
- let_it_be(:group) { create(:group) }
- let_it_be(:project) { create(:project, group: group) }
- let_it_be(:issue) { create(:issue, project: project) }
- let_it_be(:project_event2) { create(:event, :closed, project: project, target: issue) }
- let_it_be(:event_without_parent) { create(:event, :joined, project: nil, group: nil) }
- let_it_be(:group_event) { create(:event, :created, group: group, project: nil) }
- let_it_be(:project_event1) { create(:event, :created, project: project, target: issue) }
- # looks invalid but we have some records like this on PRD
-
- it 'inserts all records' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 4, reached_end_of_table: true })
-
- worker.perform
-
- expected_records = [
- hash_including('id' => project_event2.id, 'path' => "#{group.id}/#{project.project_namespace.id}/",
- 'target_type' => 'Issue'),
- hash_including('id' => event_without_parent.id, 'path' => '', 'target_type' => ''),
- hash_including('id' => group_event.id, 'path' => "#{group.id}/", 'target_type' => ''),
- hash_including('id' => project_event1.id, 'path' => "#{group.id}/#{project.project_namespace.id}/",
- 'target_type' => 'Issue')
- ]
-
- events = ClickHouse::Client.select('SELECT * FROM events ORDER BY id', :main)
-
- expect(events).to match(expected_records)
-
- last_processed_id = ClickHouse::SyncCursor.cursor_for(:events)
- expect(last_processed_id).to eq(project_event1.id)
- end
-
- context 'when multiple batches are needed' do
- before do
- stub_const("#{described_class}::BATCH_SIZE", 1)
- stub_const("#{described_class}::INSERT_BATCH_SIZE", 1)
- end
-
- it 'inserts all records' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 4, reached_end_of_table: true })
-
- worker.perform
-
- events = ClickHouse::Client.select('SELECT * FROM events', :main)
- expect(events.size).to eq(4)
- end
-
- context 'when new records are inserted while processing' do
- it 'does not process new records created during the iteration' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 4,
- reached_end_of_table: true })
-
- # Simulating the case when there is an insert during the iteration
- call_count = 0
- allow(worker).to receive(:next_batch).and_wrap_original do |method|
- call_count += 1
- create(:event) if call_count == 3
- method.call
- end
-
- worker.perform
- end
- end
- end
-
- context 'when time limit is reached' do
- before do
- stub_const("#{described_class}::BATCH_SIZE", 1)
- end
-
- it 'stops the processing' do
- allow_next_instance_of(Analytics::CycleAnalytics::RuntimeLimiter) do |runtime_limiter|
- allow(runtime_limiter).to receive(:over_time?).and_return(false, true)
- end
-
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 2, reached_end_of_table: false })
-
- worker.perform
-
- last_processed_id = ClickHouse::SyncCursor.cursor_for(:events)
- expect(last_processed_id).to eq(event_without_parent.id)
- end
- end
-
- context 'when syncing from a certain point' do
- before do
- ClickHouse::SyncCursor.update_cursor_for(:events, project_event2.id)
- end
-
- it 'syncs records after the cursor' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 3, reached_end_of_table: true })
-
- worker.perform
-
- events = ClickHouse::Client.select('SELECT id FROM events ORDER BY id', :main)
- expect(events).to eq([{ 'id' => event_without_parent.id }, { 'id' => group_event.id },
- { 'id' => project_event1.id }])
- end
-
- context 'when there is nothing to sync' do
- it 'does nothing' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result,
- { status: :processed, records_inserted: 0, reached_end_of_table: true })
-
- ClickHouse::SyncCursor.update_cursor_for(:events, project_event1.id)
- worker.perform
-
- events = ClickHouse::Client.select('SELECT id FROM events ORDER BY id', :main)
- expect(events).to be_empty
- end
- end
- end
- end
- end
-
- context 'when clickhouse is not configured' do
- before do
- allow(ClickHouse::Client).to receive(:database_configured?).and_return(false)
- end
-
- it 'skips execution' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result, { status: :disabled })
-
- worker.perform
- end
- end
- end
-
- context 'when exclusive lease error happens' do
- it 'skips execution' do
- stub_feature_flags(event_sync_worker_for_click_house: true)
- allow(ClickHouse::Client).to receive(:database_configured?).with(:main).and_return(true)
-
- expect(worker).to receive(:in_lock).and_raise(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result, { status: :skipped })
-
worker.perform
end
- end
- context 'when the event_sync_worker_for_click_house feature flag is off' do
- before do
- stub_feature_flags(event_sync_worker_for_click_house: false)
- end
-
- it 'skips execution' do
- expect(worker).to receive(:log_extra_metadata_on_done).with(:result, { status: :disabled })
+ it 'correctly logs the metadata on done' do
+ expect_next_instance_of(::ClickHouse::SyncStrategies::EventSyncStrategy) do |instance|
+ expect(instance).to receive(:execute).and_return({ status: :ok })
+ end
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:result, { status: :ok })
worker.perform
end
diff --git a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
index bba855f5095..f62c08cb7da 100644
--- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
@@ -269,6 +269,33 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
expect(import_failures.first.external_identifiers).to eq(github_identifiers.with_indifferent_access)
end
end
+
+ context 'when FailedToObtainLockError is raised' do
+ let(:exception) { Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError.new }
+
+ before do
+ expect(importer_class).to receive(:new)
+ .with(instance_of(MockRepresentation), project, client)
+ .and_return(importer_instance)
+
+ expect(importer_instance).to receive(:execute).and_raise(exception)
+ end
+
+ it 'logs the error and raises an exception' do
+ expect(Gitlab::GithubImport::Logger).to receive(:warn).with(
+ {
+ external_identifiers: github_identifiers,
+ message: 'Failed to obtaing lock for user finder. Retrying later.',
+ project_id: project.id,
+ importer: 'klass_name'
+ }
+ )
+
+ expect do
+ worker.import(project, client, { 'number' => 10, 'github_id' => 1 })
+ end.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
+ end
+ end
end
describe '#increment_object_counter?' do
diff --git a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb
index c76ce6b555f..7b8c4fab0c6 100644
--- a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb
@@ -76,7 +76,7 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods, feature_category: :imp
expect(worker.class)
.to receive(:perform_in)
- .with(15, project.id, { 'number' => 2 }, '123')
+ .with(15.012, project.id, { 'number' => 2 }, '123')
worker.perform(project.id, { 'number' => 2 }, '123')
end
@@ -100,6 +100,15 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods, feature_category: :imp
expect(worker.try_import(10, 20)).to eq(false)
end
+
+ it 'returns false when the import fails due to the FailedToObtainLockError' do
+ expect(worker)
+ .to receive(:import)
+ .with(10, 20)
+ .and_raise(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
+
+ expect(worker.try_import(10, 20)).to eq(false)
+ end
end
describe '#notify_waiter' do
diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
index 37e686f9f92..a88d819843a 100644
--- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
@@ -2,9 +2,9 @@
require 'spec_helper'
+# Most tests of StageMethods should not go here but in the shared examples instead:
+# spec/support/shared_examples/workers/gitlab/github_import/stage_methods_shared_examples.rb
RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers do
- let_it_be(:project) { create(:project, :import_started, import_url: 'https://t0ken@github.com/repo/repo.git') }
-
let(:worker) do
Class.new do
def self.name
@@ -15,200 +15,17 @@ RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers
end.new
end
- it 'has a Sidekiq retry of 6' do
- expect(worker.class.sidekiq_options['retry']).to eq(6)
- end
-
- describe '#perform' do
- it 'returns if no project could be found' do
- expect(worker).not_to receive(:try_import)
-
- worker.perform(-1)
- end
-
- it 'returns if the import state is no longer in progress' do
- allow(project.import_state).to receive(:status).and_return('failed')
-
- allow(worker)
- .to receive(:find_project)
- .with(project.id)
- .and_return(project)
-
- expect(worker).not_to receive(:try_import)
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'starting stage',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'Project import is no longer running. Stopping worker.',
- project_id: project.id,
- import_stage: 'DummyStage',
- import_status: 'failed'
- }
- )
-
- worker.perform(project.id)
- end
-
- it 'imports the data when the project exists' do
- allow(worker)
- .to receive(:find_project)
- .with(project.id)
- .and_return(project)
-
- expect(worker)
- .to receive(:try_import)
- .with(
- an_instance_of(Gitlab::GithubImport::Client),
- an_instance_of(Project)
- )
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'starting stage',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'stage finished',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
-
- worker.perform(project.id)
- end
-
- it 'logs error when import fails' do
- exception = StandardError.new('some error')
-
- allow(worker)
- .to receive(:find_project)
- .with(project.id)
- .and_return(project)
-
- expect(worker)
- .to receive(:try_import)
- .and_raise(exception)
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'starting stage',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
-
- expect(Gitlab::Import::ImportFailureService)
- .to receive(:track)
- .with(
- {
- project_id: project.id,
- exception: exception,
- error_source: 'DummyStage',
- fail_import: false,
- metrics: true
- }
- ).and_call_original
-
- expect { worker.perform(project.id) }
- .to raise_error(exception)
-
- expect(project.import_state.reload.status).to eq('started')
-
- expect(project.import_failures).not_to be_empty
- expect(project.import_failures.last.exception_class).to eq('StandardError')
- expect(project.import_failures.last.exception_message).to eq('some error')
- end
- end
-
- describe '#try_import' do
- before do
- allow(worker).to receive(:jid).and_return('jid')
- end
-
- it 'imports the project' do
- client = double(:client)
-
- expect(worker)
- .to receive(:import)
- .with(client, project)
-
- expect(Gitlab::GithubImport::RefreshImportJidWorker).to receive(:perform_in_the_future).with(project.id, 'jid')
-
- worker.try_import(client, project)
- end
-
- it 'reschedules the worker if RateLimitError was raised' do
- client = double(:client, rate_limit_resets_in: 10)
-
- expect(Gitlab::GithubImport::RefreshImportJidWorker).to receive(:perform_in_the_future).with(project.id, 'jid')
-
- expect(worker)
- .to receive(:import)
- .with(client, project)
- .and_raise(Gitlab::GithubImport::RateLimitError)
-
- expect(worker.class)
- .to receive(:perform_in)
- .with(10, project.id)
-
- worker.try_import(client, project)
- end
- end
-
- describe '#find_project' do
- it 'returns a Project for an existing ID' do
- project.import_state.update_column(:status, 'started')
-
- expect(worker.find_project(project.id)).to eq(project)
- end
-
- it 'returns nil for a project that failed importing' do
- project.import_state.update_column(:status, 'failed')
-
- expect(worker.find_project(project.id)).to be_nil
- end
-
- it 'returns nil for a non-existing project ID' do
- expect(worker.find_project(-1)).to be_nil
- end
- end
-
- describe '.sidekiq_options!' do
- subject(:sidekiq_options) { worker.class.sidekiq_options }
+ describe '.max_retries_after_interruption!' do
+ subject(:max_retries_after_interruption) { worker.class.sidekiq_options['max_retries_after_interruption'] }
it 'does not set the `max_retries_after_interruption` if not called' do
- is_expected.not_to have_key('max_retries_after_interruption')
+ is_expected.to be_nil
end
it 'sets the `max_retries_after_interruption`' do
worker.class.resumes_work_when_interrupted!
- is_expected.to include('max_retries_after_interruption' => 20)
- end
-
- it 'sets the status_expiration' do
- is_expected.to include('status_expiration' => Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION)
+ is_expected.to eq(20)
end
end
end
diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb
index 9e8fad19c20..7f400ce791d 100644
--- a/spec/workers/emails_on_push_worker_spec.rb
+++ b/spec/workers/emails_on_push_worker_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe EmailsOnPushWorker, :mailer, feature_category: :source_code_manag
describe "#perform" do
context "when push is a new branch" do
before do
- data_new_branch = data.stringify_keys.merge("before" => Gitlab::Git::BLANK_SHA)
+ data_new_branch = data.stringify_keys.merge("before" => Gitlab::Git::SHA1_BLANK_SHA)
subject.perform(project.id, recipients, data_new_branch)
end
@@ -34,7 +34,7 @@ RSpec.describe EmailsOnPushWorker, :mailer, feature_category: :source_code_manag
context "when push is a deleted branch" do
before do
- data_deleted_branch = data.stringify_keys.merge("after" => Gitlab::Git::BLANK_SHA)
+ data_deleted_branch = data.stringify_keys.merge("after" => Gitlab::Git::SHA1_BLANK_SHA)
subject.perform(project.id, recipients, data_deleted_branch)
end
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index c60e8d37c2e..4067bce8d8d 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -163,7 +163,6 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do
'Ci::InitialPipelineProcessWorker' => 3,
'Ci::MergeRequests::AddTodoWhenBuildFailsWorker' => 3,
'Ci::Minutes::UpdateProjectAndNamespaceUsageWorker' => 3,
- 'Ci::Llm::GenerateConfigWorker' => 3,
'Ci::PipelineArtifacts::CoverageReportWorker' => 3,
'Ci::PipelineArtifacts::CreateQualityReportWorker' => 3,
'Ci::PipelineCleanupRefWorker' => 3,
@@ -280,6 +279,7 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do
'Gitlab::GithubImport::PullRequests::ImportMergedByWorker' => 5,
'Gitlab::GithubImport::ImportPullRequestWorker' => 5,
'Gitlab::GithubImport::RefreshImportJidWorker' => 5,
+ 'Gitlab::GithubImport::ReplayEventsWorker' => 5,
'Gitlab::GithubImport::Stage::FinishImportWorker' => 6,
'Gitlab::GithubImport::Stage::ImportBaseDataWorker' => 6,
'Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker' => 6,
diff --git a/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb b/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb
index d4cd1b82349..1141d08729d 100644
--- a/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb
+++ b/spec/workers/gitlab/bitbucket_server_import/stage/import_users_worker_spec.rb
@@ -3,7 +3,14 @@
require 'spec_helper'
RSpec.describe Gitlab::BitbucketServerImport::Stage::ImportUsersWorker, feature_category: :importers do
- let_it_be(:project) { create(:project, :import_started) }
+ let_it_be(:project) do
+ create(:project, :import_started,
+ import_data_attributes: {
+ data: { 'project_key' => 'key', 'repo_slug' => 'slug' },
+ credentials: { 'base_uri' => 'http://bitbucket.org/', 'user' => 'bitbucket', 'password' => 'password' }
+ }
+ )
+ end
let(:worker) { described_class.new }
@@ -15,6 +22,12 @@ RSpec.describe Gitlab::BitbucketServerImport::Stage::ImportUsersWorker, feature_
allow_next_instance_of(Gitlab::BitbucketServerImport::Importers::UsersImporter) do |importer|
allow(importer).to receive(:execute)
end
+
+ allow(Gitlab::BitbucketServerImport::Stage::ImportPullRequestsWorker).to receive(:perform_async).and_return(nil)
+ end
+
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { [project.id] }
end
it 'schedules the next stage' do
diff --git a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb
index aa8243154ef..cbe27934bd5 100644
--- a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb
@@ -5,16 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: :importers do
subject(:worker) { described_class.new }
- describe '#import' do
- let(:import_state) { create(:import_state, :started) }
-
- let(:project) do
- instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state)
+ describe '#execute' do
+ let_it_be(:project) do
+ create(:project, import_url: 'https://github.com/foo/bar.git', import_state: create(:import_state, :started))
end
- let(:client) { instance_double('Gitlab::GithubImport::Client') }
- let(:importer) { instance_double('Gitlab::GithubImport::Importer::IssueEventImporter') }
-
+ let(:client) { instance_double(Gitlab::GithubImport::Client) }
+ let(:extended_events) { true }
let(:event_hash) do
{
'id' => 6501124486,
@@ -29,23 +26,55 @@ RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: :
}
end
- it 'imports an issue event' do
- expect(Gitlab::GithubImport::Importer::IssueEventImporter)
- .to receive(:new)
- .with(
- an_instance_of(Gitlab::GithubImport::Representation::IssueEvent),
- project,
- client
- )
- .and_return(importer)
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting|
+ allow(setting).to receive(:extended_events?).and_return(extended_events)
+ end
+ end
- expect(importer).to receive(:execute)
+ it 'imports an issue event and increase importer counter' do
+ expect_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter,
+ an_instance_of(Gitlab::GithubImport::Representation::IssueEvent),
+ project,
+ client
+ ) do |importer|
+ expect(importer).to receive(:execute)
+ end
expect(Gitlab::GithubImport::ObjectCounter)
.to receive(:increment)
+ .with(project, :issue_event, :imported)
.and_call_original
worker.import(project, client, event_hash)
end
+
+ context 'when event should increment a mapped importer counter' do
+ before do
+ stub_const('Gitlab::GithubImport::Importer::IssueEventImporter::EVENT_COUNTER_MAP', {
+ 'closed' => 'custom_type'
+ })
+
+ allow_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter) do |importer|
+ allow(importer).to receive(:execute)
+ end
+ end
+
+ it 'increments the mapped importer counter' do
+ expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, 'custom_type', :imported)
+
+ worker.import(project, client, event_hash)
+ end
+
+ context 'when extended_events is disabled' do
+ let(:extended_events) { false }
+
+ it 'increments the issue_event importer counter' do
+ expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, :issue_event, :imported)
+
+ worker.import(project, client, event_hash)
+ end
+ end
+ end
end
end
diff --git a/spec/workers/gitlab/github_import/replay_events_worker_spec.rb b/spec/workers/gitlab/github_import/replay_events_worker_spec.rb
new file mode 100644
index 00000000000..99c9e838bbf
--- /dev/null
+++ b/spec/workers/gitlab/github_import/replay_events_worker_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ReplayEventsWorker, feature_category: :importers do
+ let_it_be(:project) { create(:project, import_state: create(:import_state, :started)) }
+ let(:client) { instance_double(Gitlab::GithubImport::Client) }
+
+ let(:worker) { described_class.new }
+
+ describe '#import' do
+ it 'call replay events importer' do
+ hash = {
+ 'issuable_iid' => 1,
+ 'issuable_type' => 'Issue'
+ }
+
+ expect_next_instance_of(Gitlab::GithubImport::Importer::ReplayEventsImporter,
+ an_instance_of(Gitlab::GithubImport::Representation::ReplayEvent), project, client) do |importer|
+ expect(importer).to receive(:execute)
+ end
+
+ expect(Gitlab::GithubImport::ObjectCounter).not_to receive(:increment)
+
+ worker.import(project, client, hash)
+ end
+ end
+
+ describe '#object_type' do
+ it { expect(worker.object_type).to eq(:replay_event) }
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
index 6d8fa29bd27..ba8fcdb2406 100644
--- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
+
+ subject(:worker) { described_class.new }
it_behaves_like Gitlab::GithubImport::StageMethods
diff --git a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb
index c8b528593b9..75c9ab96751 100644
--- a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb
@@ -3,12 +3,13 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker, feature_category: :importers do
- subject(:worker) { described_class.new }
-
let_it_be(:project) { create(:project) }
- let(:settings) { ::Gitlab::GithubImport::Settings.new(project) }
+
+ let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) }
let(:stage_enabled) { true }
+ subject(:worker) { described_class.new }
+
before do
settings.write({ optional_stages: { attachments_import: stage_enabled } })
end
diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb
index b8f2db8e2d9..49dc905f430 100644
--- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb
@@ -4,12 +4,12 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker, feature_category: :importers do
let_it_be(:project) { create(:project) }
- let_it_be(:import_state) { create(:import_state, project: project) }
- let(:worker) { described_class.new }
let(:importer) { double(:importer) }
let(:client) { double(:client) }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb
index 6a55f575da8..7a085227b36 100644
--- a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb
@@ -4,14 +4,14 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportCollaboratorsWorker, feature_category: :importers do
let_it_be(:project) { create(:project) }
- let_it_be(:import_state) { create(:import_state, project: project) }
+
let(:settings) { Gitlab::GithubImport::Settings.new(project) }
let(:stage_enabled) { true }
-
- let(:worker) { described_class.new }
let(:importer) { instance_double(Gitlab::GithubImport::Importer::CollaboratorsImporter) }
let(:client) { instance_double(Gitlab::GithubImport::Client) }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb
index bad3a5beb0e..6b01f2825e4 100644
--- a/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb
@@ -3,15 +3,19 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker, feature_category: :importers do
- subject(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
- let(:project) { create(:project) }
let!(:group) { create(:group, projects: [project]) }
- let(:settings) { ::Gitlab::GithubImport::Settings.new(project) }
+ let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) }
let(:stage_enabled) { true }
+ let(:extended_events) { false }
+
+ subject(:worker) { described_class.new }
before do
- settings.write({ optional_stages: { single_endpoint_issue_events_import: stage_enabled } })
+ settings.write({
+ optional_stages: { single_endpoint_issue_events_import: stage_enabled }, extended_events: extended_events
+ })
end
it_behaves_like Gitlab::GithubImport::StageMethods
@@ -48,6 +52,18 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker, feature_cat
worker.import(client, project)
end
+
+ context 'when extended_events is enabled' do
+ let(:extended_events) { true }
+
+ it 'does not skip the stage' do
+ expect_next_instance_of(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter) do |importer|
+ expect(importer).to receive(:execute).and_return(Gitlab::JobWaiter.new)
+ end
+
+ worker.import(client, project)
+ end
+ end
end
end
end
diff --git a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
index 10f6ebfbab9..bc829e6124c 100644
--- a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
@@ -3,12 +3,13 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
- let(:settings) { ::Gitlab::GithubImport::Settings.new(project) }
+ let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) }
let(:single_endpoint_optional_stage) { true }
+ subject(:worker) { described_class.new }
+
before do
settings.write({ optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } })
end
diff --git a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb
index 40194a91b3a..a0b2f82f378 100644
--- a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb
@@ -3,14 +3,16 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
+
+ subject(:worker) { described_class.new }
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
it 'imports all the lfs objects' do
- importer = double(:importer)
+ importer = instance_double(Gitlab::GithubImport::Importer::LfsObjectsImporter)
+ client = instance_double(Gitlab::GithubImport::Client)
waiter = Gitlab::JobWaiter.new(2, '123')
expect(Gitlab::GithubImport::Importer::LfsObjectsImporter)
@@ -26,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker, feature_cate
.to receive(:perform_async)
.with(project.id, { '123' => 2 }, 'finish')
- worker.import(project)
+ worker.import(client, project)
end
end
end
diff --git a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
index 69078a666a5..a8b40ff43d2 100644
--- a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
@@ -3,12 +3,13 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
- let(:settings) { ::Gitlab::GithubImport::Settings.new(project) }
+ let(:settings) { ::Gitlab::GithubImport::Settings.new(project.reload) }
let(:single_endpoint_optional_stage) { true }
+ subject(:worker) { described_class.new }
+
before do
settings.write({ optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } })
end
diff --git a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb
index b73f8c6524d..dcc6b3d2311 100644
--- a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb
@@ -4,12 +4,12 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker, feature_category: :importers do
let_it_be(:project) { create(:project) }
- let_it_be(:import_state) { create(:import_state, project: project) }
- let(:worker) { described_class.new }
let(:importer) { instance_double('Gitlab::GithubImport::Importer::ProtectedBranchImporter') }
let(:client) { instance_double('Gitlab::GithubImport::Client') }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb
index b214f6a97d4..b3cb73c5fa0 100644
--- a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb
@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:import_state) { create(:import_state, project: project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
+
+ subject(:worker) { described_class.new }
it_behaves_like Gitlab::GithubImport::StageMethods
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb
index 4468de7e691..c7b73357e76 100644
--- a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb
@@ -3,14 +3,14 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWorker, feature_category: :importers do
- subject(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
- let(:project) { instance_double(Project, id: 1, import_state: import_state) }
- let(:import_state) { instance_double(ProjectImportState) }
let(:client) { instance_double(Gitlab::GithubImport::Client) }
let(:importer) { instance_double(Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImporter) }
let(:waiter) { Gitlab::JobWaiter.new(2, '123') }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb
index 48b41435adb..ab3f0b43304 100644
--- a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb
@@ -3,11 +3,12 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker, feature_category: :importers do
- let(:project) { create(:project) }
- let(:import_state) { create(:import_state, project: project) }
- let(:worker) { described_class.new }
+ let_it_be(:project) { create(:project) }
+
let(:client) { double(:client) }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
index 2ea66d8cdf3..2c1beb29fa1 100644
--- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
@@ -4,13 +4,13 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_category: :importers do
let_it_be(:project) { create(:project) }
- let_it_be(:import_state) { create(:import_state, project: project) }
- let(:options) { { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } }
- let(:worker) { described_class.new }
+ let(:options) { { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } }
let(:importer) { double(:importer) }
let(:client) { double(:client) }
+ subject(:worker) { described_class.new }
+
it_behaves_like Gitlab::GithubImport::StageMethods
describe '#import' do
diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb
index 020f7539bf4..e61b46124b3 100644
--- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb
@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker, feature_category: :importers do
- let_it_be(:project) { create(:project, :import_started) }
+ let_it_be(:project) { create(:project) }
- let(:worker) { described_class.new }
+ subject(:worker) { described_class.new }
it_behaves_like Gitlab::GithubImport::StageMethods
diff --git a/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb b/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb
index 7aea40807e8..e86d6771386 100644
--- a/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb
+++ b/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb
@@ -23,15 +23,15 @@ RSpec.describe GoogleCloud::CreateCloudsqlInstanceWorker, feature_category: :sha
described_class.new.perform(user_id, project_id, worker_options)
end
- it 'calls GoogleCloud::SetupCloudsqlInstanceService' do
- allow_next_instance_of(GoogleCloud::SetupCloudsqlInstanceService) do |service|
+ it 'calls CloudSeed::GoogleCloud::SetupCloudsqlInstanceService' do
+ allow_next_instance_of(CloudSeed::GoogleCloud::SetupCloudsqlInstanceService) do |service|
expect(service).to receive(:execute).and_return({ status: :success })
end
subject
end
- context 'when GoogleCloud::SetupCloudsqlInstanceService fails' do
+ context 'when CloudSeed::GoogleCloud::SetupCloudsqlInstanceService fails' do
subject do
user_id = random_user.id
project_id = project.id
@@ -39,7 +39,7 @@ RSpec.describe GoogleCloud::CreateCloudsqlInstanceWorker, feature_category: :sha
end
it 'raises error' do
- allow_next_instance_of(GoogleCloud::SetupCloudsqlInstanceService) do |service|
+ allow_next_instance_of(CloudSeed::GoogleCloud::SetupCloudsqlInstanceService) do |service|
expect(service).to receive(:execute).and_return({ status: :error })
end
diff --git a/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb b/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb
index bdafc076465..2a7d52d987f 100644
--- a/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb
+++ b/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe GoogleCloud::FetchGoogleIpListWorker, feature_category: :build_artifacts do
describe '#perform' do
it 'returns success' do
- allow_next_instance_of(GoogleCloud::FetchGoogleIpListService) do |service|
+ allow_next_instance_of(CloudSeed::GoogleCloud::FetchGoogleIpListService) do |service|
expect(service).to receive(:execute).and_return({ status: :success })
end
diff --git a/spec/workers/jira_connect/sync_project_worker_spec.rb b/spec/workers/jira_connect/sync_project_worker_spec.rb
index b617508bb3a..83bce97cd51 100644
--- a/spec/workers/jira_connect/sync_project_worker_spec.rb
+++ b/spec/workers/jira_connect/sync_project_worker_spec.rb
@@ -51,11 +51,11 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep, feature_c
end
it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new { perform(project.id, update_sequence_id) }.count
+ control = ActiveRecord::QueryRecorder.new { perform(project.id, update_sequence_id) }
create(:merge_request, :unique_branches, title: 'TEST-123')
- expect { perform(project.id, update_sequence_id) }.not_to exceed_query_limit(control_count)
+ expect { perform(project.id, update_sequence_id) }.not_to exceed_query_limit(control)
end
context 'with branches to sync' do
diff --git a/spec/workers/new_issue_worker_spec.rb b/spec/workers/new_issue_worker_spec.rb
index 540296374ef..b9cbf974a69 100644
--- a/spec/workers/new_issue_worker_spec.rb
+++ b/spec/workers/new_issue_worker_spec.rb
@@ -99,6 +99,14 @@ RSpec.describe NewIssueWorker, feature_category: :team_planning do
expect(Event.last).to have_attributes(target_id: issue.id, target_type: 'WorkItem')
end
end
+
+ context 'when skip_notifications is true' do
+ it 'does not call NotificationService' do
+ expect(NotificationService).not_to receive(:new)
+
+ worker.perform(issue.id, user.id, issue.class.name, true)
+ end
+ end
end
end
end
diff --git a/spec/workers/releases/publish_event_worker_spec.rb b/spec/workers/releases/publish_event_worker_spec.rb
new file mode 100644
index 00000000000..86dd09a756f
--- /dev/null
+++ b/spec/workers/releases/publish_event_worker_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Releases::PublishEventWorker, feature_category: :release_evidence do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be_with_reload(:release) { create(:release, project: project, released_at: Time.current) }
+
+ before do
+ allow(Gitlab::EventStore).to receive(:publish).and_return(true)
+ end
+
+ describe 'when the releases feature is not disabled' do
+ before do
+ project.update!(releases_access_level: 'enabled')
+ described_class.new.perform
+ end
+
+ it 'broadcasts the published event' do
+ expect(Gitlab::EventStore).to have_received(:publish).with(Projects::ReleasePublishedEvent)
+ end
+
+ it 'sets the release as published' do
+ expect(release.release_published_at).not_to be_nil
+ end
+ end
+
+ describe 'when the releases feature is disabled' do
+ before do
+ project.update!(releases_access_level: 'disabled')
+ described_class.new.perform
+ end
+
+ it 'does not broadcasts the published event' do
+ expect(Gitlab::EventStore).not_to have_received(:publish).with(Projects::ReleasePublishedEvent)
+ end
+
+ # Having a release created with the releases feature disabled is a bogus state anyway.
+ # Setting it as published prevents having such releases piling up forever in the
+ # `unpublished` scope.
+ it 'sets the release as published' do
+ expect(release.release_published_at).not_to be_nil
+ end
+ end
+end