diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/workers | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/workers')
34 files changed, 723 insertions, 271 deletions
diff --git a/spec/workers/bulk_import_worker_spec.rb b/spec/workers/bulk_import_worker_spec.rb index 7e301efe708..0d0b81d2ec0 100644 --- a/spec/workers/bulk_import_worker_spec.rb +++ b/spec/workers/bulk_import_worker_spec.rb @@ -87,7 +87,6 @@ RSpec.describe BulkImportWorker do create(:bulk_import_entity, :created, bulk_import: bulk_import) expect(described_class).to receive(:perform_in).with(described_class::PERFORM_DELAY, bulk_import.id) - expect(BulkImports::EntityWorker).to receive(:perform_async).twice expect(BulkImports::ExportRequestWorker).to receive(:perform_async).twice subject.perform(bulk_import.id) @@ -111,7 +110,7 @@ RSpec.describe BulkImportWorker do bulk_import = create(:bulk_import, :created) create(:bulk_import_entity, :created, bulk_import: bulk_import) - allow(BulkImports::EntityWorker).to receive(:perform_async).and_raise(StandardError) + allow(BulkImports::ExportRequestWorker).to receive(:perform_async).and_raise(StandardError) expect(Gitlab::ErrorTracking).to receive(:track_exception).with(kind_of(StandardError), bulk_import_id: bulk_import.id) diff --git a/spec/workers/bulk_imports/entity_worker_spec.rb b/spec/workers/bulk_imports/entity_worker_spec.rb index ab85b587975..0fcdbccc304 100644 --- a/spec/workers/bulk_imports/entity_worker_spec.rb +++ b/spec/workers/bulk_imports/entity_worker_spec.rb @@ -37,9 +37,11 @@ RSpec.describe BulkImports::EntityWorker do .to receive(:info).twice .with( hash_including( - 'entity_id' => entity.id, + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, 'current_stage' => nil, - 'message' => 'Stage starting' + 'message' => 'Stage starting', + 'importer' => 'gitlab_migration' ) ) end @@ -67,8 +69,10 @@ RSpec.describe BulkImports::EntityWorker do .to receive(:info).twice .with( hash_including( - 'entity_id' => entity.id, - 'current_stage' => nil + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'current_stage' => nil, + 'importer' => 'gitlab_migration' ) ) @@ -76,16 +80,23 @@ RSpec.describe BulkImports::EntityWorker do .to receive(:error) .with( hash_including( - 'entity_id' => entity.id, + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, 'current_stage' => nil, - 'message' => 'Error!' + 'message' => 'Error!', + 'importer' => 'gitlab_migration' ) ) end expect(Gitlab::ErrorTracking) .to receive(:track_exception) - .with(exception, entity_id: entity.id) + .with( + exception, + bulk_import_entity_id: entity.id, + bulk_import_id: entity.bulk_import_id, + importer: 'gitlab_migration' + ) subject end @@ -99,9 +110,11 @@ RSpec.describe BulkImports::EntityWorker do .to receive(:info).twice .with( hash_including( - 'entity_id' => entity.id, + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, 'current_stage' => 0, - 'message' => 'Stage running' + 'message' => 'Stage running', + 'importer' => 'gitlab_migration' ) ) end @@ -127,8 +140,10 @@ RSpec.describe BulkImports::EntityWorker do .to receive(:info).twice .with( hash_including( - 'entity_id' => entity.id, - 'current_stage' => 0 + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'current_stage' => 0, + 'importer' => 'gitlab_migration' ) ) end diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb index a7f7aaa7dba..597eed3a9b9 100644 --- a/spec/workers/bulk_imports/export_request_worker_spec.rb +++ b/spec/workers/bulk_imports/export_request_worker_spec.rb @@ -21,38 +21,128 @@ RSpec.describe BulkImports::ExportRequestWorker do shared_examples 'requests relations export for api resource' do include_examples 'an idempotent worker' do - it 'requests relations export' do + it 'requests relations export & schedules entity worker' do expect_next_instance_of(BulkImports::Clients::HTTP) do |client| expect(client).to receive(:post).with(expected).twice end + expect(BulkImports::EntityWorker).to receive(:perform_async).twice + perform_multiple(job_args) end context 'when network error is raised' do - it 'logs export failure and marks entity as failed' do + let(:exception) { BulkImports::NetworkError.new('Export error') } + + before do + allow_next_instance_of(BulkImports::Clients::HTTP) do |client| + allow(client).to receive(:post).and_raise(exception).twice + end + end + + context 'when error is retriable' do + it 'logs retry request and reenqueues' do + allow(exception).to receive(:retriable?).twice.and_return(true) + + expect(Gitlab::Import::Logger).to receive(:error).with( + hash_including( + 'bulk_import_entity_id' => entity.id, + 'pipeline_class' => 'ExportRequestWorker', + 'exception_class' => 'BulkImports::NetworkError', + 'exception_message' => 'Export error', + 'bulk_import_id' => bulk_import.id, + 'bulk_import_entity_type' => entity.source_type, + 'importer' => 'gitlab_migration', + 'message' => 'Retrying export request' + ) + ).twice + + expect(described_class).to receive(:perform_in).twice.with(2.seconds, entity.id) + + perform_multiple(job_args) + end + end + + context 'when error is not retriable' do + it 'logs export failure and marks entity as failed' do + expect(Gitlab::Import::Logger).to receive(:error).with( + hash_including( + 'bulk_import_entity_id' => entity.id, + 'pipeline_class' => 'ExportRequestWorker', + 'exception_class' => 'BulkImports::NetworkError', + 'exception_message' => 'Export error', + 'correlation_id_value' => anything, + 'bulk_import_id' => bulk_import.id, + 'bulk_import_entity_type' => entity.source_type, + 'importer' => 'gitlab_migration' + ) + ).twice + + perform_multiple(job_args) + + failure = entity.failures.last + + expect(failure.pipeline_class).to eq('ExportRequestWorker') + expect(failure.exception_message).to eq('Export error') + end + end + end + + context 'when source id is nil' do + let(:entity_source_id) { 'gid://gitlab/Model/1234567' } + + before do + graphql_client = instance_double(BulkImports::Clients::Graphql) + response = double(original_hash: { 'data' => { entity.entity_type => { 'id' => entity_source_id } } }) + + allow(BulkImports::Clients::Graphql).to receive(:new).and_return(graphql_client) + allow(graphql_client).to receive(:parse) + allow(graphql_client).to receive(:execute).and_return(response) + end + + it 'updates entity source id & requests export using source id' do expect_next_instance_of(BulkImports::Clients::HTTP) do |client| - expect(client).to receive(:post).and_raise(BulkImports::NetworkError, 'Export error').twice + expect(client) + .to receive(:post) + .with("/#{entity.pluralized_name}/1234567/export_relations") + .twice end - expect(Gitlab::Import::Logger).to receive(:error).with( - hash_including( - 'bulk_import_entity_id' => entity.id, - 'pipeline_class' => 'ExportRequestWorker', - 'exception_class' => 'BulkImports::NetworkError', - 'exception_message' => 'Export error', - 'correlation_id_value' => anything, - 'bulk_import_id' => bulk_import.id, - 'bulk_import_entity_type' => entity.source_type - ) - ).twice + entity.update!(source_xid: nil) perform_multiple(job_args) - failure = entity.failures.last + expect(entity.reload.source_xid).to eq(1234567) + end + + 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 + expect_next_instance_of(BulkImports::Clients::HTTP) do |client| + expect(client).to receive(:post).with(full_path_url).twice + end + + entity.update!(source_xid: nil) - expect(failure.pipeline_class).to eq('ExportRequestWorker') - expect(failure.exception_message).to eq('Export error') + expect(Gitlab::Import::Logger).to receive(:error).with( + a_hash_including( + 'message' => 'Failed to fetch source entity id', + 'bulk_import_entity_id' => entity.id, + 'pipeline_class' => 'ExportRequestWorker', + 'exception_class' => 'NoMethodError', + 'exception_message' => "undefined method `model_id' for nil:NilClass", + 'correlation_id_value' => anything, + 'bulk_import_id' => bulk_import.id, + 'bulk_import_entity_type' => entity.source_type, + 'importer' => 'gitlab_migration' + ) + ).twice + + perform_multiple(job_args) + + expect(entity.source_xid).to be_nil + end end end end @@ -60,14 +150,16 @@ RSpec.describe BulkImports::ExportRequestWorker do context 'when entity is group' do let(:entity) { create(:bulk_import_entity, :group_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) } - let(:expected) { '/groups/foo%2Fbar/export_relations' } + let(:expected) { "/groups/#{entity.source_xid}/export_relations" } + let(:full_path_url) { '/groups/foo%2Fbar/export_relations' } include_examples 'requests relations export for api resource' end context 'when entity is project' do let(:entity) { create(:bulk_import_entity, :project_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) } - let(:expected) { '/projects/foo%2Fbar/export_relations' } + let(:expected) { "/projects/#{entity.source_xid}/export_relations" } + let(:full_path_url) { '/projects/foo%2Fbar/export_relations' } include_examples 'requests relations export for api resource' end diff --git a/spec/workers/bulk_imports/pipeline_worker_spec.rb b/spec/workers/bulk_imports/pipeline_worker_spec.rb index fe2039bd79e..ee65775f170 100644 --- a/spec/workers/bulk_imports/pipeline_worker_spec.rb +++ b/spec/workers/bulk_imports/pipeline_worker_spec.rb @@ -37,7 +37,9 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_name' => 'FakePipeline', - 'entity_id' => entity.id + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'importer' => 'gitlab_migration' ) ) end @@ -83,8 +85,10 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_tracker_id' => pipeline_tracker.id, - 'entity_id' => entity.id, - 'message' => 'Unstarted pipeline not found' + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'message' => 'Unstarted pipeline not found', + 'importer' => 'gitlab_migration' ) ) end @@ -120,8 +124,10 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_name' => 'FakePipeline', - 'entity_id' => entity.id, - 'message' => 'Error!' + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'message' => 'Error!', + 'importer' => 'gitlab_migration' ) ) end @@ -130,8 +136,10 @@ RSpec.describe BulkImports::PipelineWorker do .to receive(:track_exception) .with( instance_of(StandardError), - entity_id: entity.id, - pipeline_name: pipeline_tracker.pipeline_name + bulk_import_entity_id: entity.id, + bulk_import_id: entity.bulk_import_id, + pipeline_name: pipeline_tracker.pipeline_name, + importer: 'gitlab_migration' ) expect(BulkImports::EntityWorker) @@ -160,7 +168,7 @@ RSpec.describe BulkImports::PipelineWorker do end context 'when entity is failed' do - it 'marks tracker as failed and logs the error' do + it 'marks tracker as skipped and logs the skip' do pipeline_tracker = create( :bulk_import_tracker, entity: entity, @@ -170,22 +178,25 @@ RSpec.describe BulkImports::PipelineWorker do entity.update!(status: -1) - expect(BulkImports::Failure).to receive(:create) expect_next_instance_of(Gitlab::Import::Logger) do |logger| + allow(logger).to receive(:info) + expect(logger) - .to receive(:error) + .to receive(:info) .with( hash_including( 'pipeline_name' => 'FakePipeline', - 'entity_id' => entity.id, - 'message' => 'Failed entity status' + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'message' => 'Skipping pipeline due to failed entity', + 'importer' => 'gitlab_migration' ) ) end subject.perform(pipeline_tracker.id, pipeline_tracker.stage, entity.id) - expect(pipeline_tracker.reload.status_name).to eq(:failed) + expect(pipeline_tracker.reload.status_name).to eq(:skipped) end end @@ -224,7 +235,9 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_name' => 'FakePipeline', - 'entity_id' => entity.id + 'bulk_import_entity_id' => entity.id, + 'bulk_import_id' => entity.bulk_import_id, + 'importer' => 'gitlab_migration' ) ) end @@ -347,8 +360,10 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_name' => 'NdjsonPipeline', - 'entity_id' => entity.id, - 'message' => 'Pipeline timeout' + 'bulk_import_entity_id' => entity.id, + 'message' => 'Pipeline timeout', + 'bulk_import_id' => entity.bulk_import_id, + 'importer' => 'gitlab_migration' ) ) end @@ -374,8 +389,10 @@ RSpec.describe BulkImports::PipelineWorker do .with( hash_including( 'pipeline_name' => 'NdjsonPipeline', - 'entity_id' => entity.id, - 'message' => 'Error!' + 'bulk_import_entity_id' => entity.id, + 'message' => 'Export from source instance failed: Error!', + 'bulk_import_id' => entity.bulk_import_id, + 'importer' => 'gitlab_migration' ) ) end diff --git a/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb b/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb new file mode 100644 index 00000000000..57bbd8a6ff0 --- /dev/null +++ b/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::ParseSecureFileMetadataWorker do + describe '#perform' do + include_examples 'an idempotent worker' do + let(:secure_file) { create(:ci_secure_file) } + subject { described_class.new.perform(secure_file&.id) } + + context 'when the file is found' do + it 'calls update_metadata!' do + allow(::Ci::SecureFile).to receive(:find_by_id).and_return(secure_file) + expect(secure_file).to receive(:update_metadata!) + + subject + end + end + end + + context 'when file is not found' do + let(:secure_file) { nil } + + it 'does not call update_metadata!' do + expect(secure_file).not_to receive(:update_metadata!) + + subject + end + end + end +end diff --git a/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb index cb2cf58d50b..3b33972c76f 100644 --- a/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb +++ b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb @@ -27,15 +27,18 @@ RSpec.describe Ci::PipelineSuccessUnlockArtifactsWorker do end context 'when pipeline exists' do - let(:pipeline) { create(:ci_pipeline, :success, :with_job) } + let!(:pipeline) { create(:ci_pipeline, :success, :with_job) } let(:pipeline_id) { pipeline.id } - context 'when pipeline has artifacts' do - before do - create(:ci_job_artifact, job: pipeline.builds.first) - end + before do + allow(Ci::Pipeline).to receive(:find_by_id).with(pipeline.id).and_return(pipeline) + allow(pipeline).to receive(:has_erasable_artifacts?).and_return(has_erasable_artifacts) + end - it 'calls the service' do + context 'when pipeline has erasable artifacts' do + let(:has_erasable_artifacts) { true } + + it 'calls the unlock service' do service = spy(Ci::UnlockArtifactsService) expect(Ci::UnlockArtifactsService).to receive(:new).and_return(service) @@ -45,8 +48,10 @@ RSpec.describe Ci::PipelineSuccessUnlockArtifactsWorker do end end - context 'when pipeline does not have artifacts' do - it 'does not call service' do + context 'when pipeline has no erasable artifacts' do + let(:has_erasable_artifacts) { false } + + it 'does not call the unlock service' do expect(Ci::UnlockArtifactsService).not_to receive(:new) perform 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 5a32c1b40bb..ece0c5053cb 100644 --- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb @@ -159,11 +159,13 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do .with( project_id: project.id, exception: exception, - error_source: 'klass_name' + error_source: 'klass_name', + fail_import: false ) .and_call_original - worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) + expect { worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) } + .to raise_error(exception) expect(project.import_state.reload.status).to eq('started') @@ -193,4 +195,12 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do end end end + + describe '#increment_object_counter?' do + let(:issue) { double(:issue, pull_request?: true) } + + it 'returns true' do + expect(worker).to be_increment_object_counter(issue) + end + end end diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index 6b67c2b474c..322f516fbeb 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -225,7 +225,6 @@ RSpec.describe 'Every Sidekiq worker' do 'Environments::CanaryIngress::UpdateWorker' => false, 'Epics::UpdateEpicsDatesWorker' => 3, 'ErrorTrackingIssueLinkWorker' => 3, - 'Experiments::RecordConversionEventWorker' => 3, 'ExportCsvWorker' => 3, 'ExternalServiceReactiveCachingWorker' => 3, 'FileHookWorker' => false, @@ -258,6 +257,10 @@ RSpec.describe 'Every Sidekiq worker' do 'GitGarbageCollectWorker' => false, 'Gitlab::GithubImport::AdvanceStageWorker' => 3, 'Gitlab::GithubImport::ImportReleaseAttachmentsWorker' => 5, + 'Gitlab::GithubImport::Attachments::ImportReleaseWorker' => 5, + 'Gitlab::GithubImport::Attachments::ImportNoteWorker' => 5, + 'Gitlab::GithubImport::Attachments::ImportIssueWorker' => 5, + 'Gitlab::GithubImport::Attachments::ImportMergeRequestWorker' => 5, 'Gitlab::GithubImport::ImportDiffNoteWorker' => 5, 'Gitlab::GithubImport::ImportIssueWorker' => 5, 'Gitlab::GithubImport::ImportIssueEventWorker' => 5, @@ -344,10 +347,10 @@ RSpec.describe 'Every Sidekiq worker' do 'Metrics::Dashboard::PruneOldAnnotationsWorker' => 3, 'Metrics::Dashboard::SyncDashboardsWorker' => 3, 'MigrateExternalDiffsWorker' => 3, - 'Namespaces::OnboardingIssueCreatedWorker' => 3, - 'Namespaces::OnboardingPipelineCreatedWorker' => 3, - 'Namespaces::OnboardingProgressWorker' => 3, - 'Namespaces::OnboardingUserAddedWorker' => 3, + 'Onboarding::IssueCreatedWorker' => 3, + 'Onboarding::PipelineCreatedWorker' => 3, + 'Onboarding::ProgressWorker' => 3, + 'Onboarding::UserAddedWorker' => 3, 'Namespaces::RefreshRootStatisticsWorker' => 3, 'Namespaces::RootStatisticsWorker' => 3, 'Namespaces::ScheduleAggregationWorker' => 3, diff --git a/spec/workers/experiments/record_conversion_event_worker_spec.rb b/spec/workers/experiments/record_conversion_event_worker_spec.rb deleted file mode 100644 index 05e4ebc13ba..00000000000 --- a/spec/workers/experiments/record_conversion_event_worker_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Experiments::RecordConversionEventWorker, '#perform' do - subject(:perform) { described_class.new.perform(:experiment_key, 1234) } - - before do - stub_experiment(experiment_key: experiment_active) - end - - context 'when the experiment is active' do - let(:experiment_active) { true } - - include_examples 'an idempotent worker' do - subject { perform } - - it 'records the event' do - expect(Experiment).to receive(:record_conversion_event).with(:experiment_key, 1234) - - perform - end - end - end - - context 'when the experiment is not active' do - let(:experiment_active) { false } - - it 'records the event' do - expect(Experiment).not_to receive(:record_conversion_event) - - perform - end - end -end diff --git a/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb new file mode 100644 index 00000000000..6d617755861 --- /dev/null +++ b/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Attachments::ImportIssueWorker 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) + end + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + + it 'imports an issue attachments' do + expect_next_instance_of( + Gitlab::GithubImport::Importer::NoteAttachmentsImporter, + an_instance_of(Gitlab::GithubImport::Representation::NoteText), + project, + client + ) do |note_attachments_importer| + expect(note_attachments_importer).to receive(:execute) + end + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import(project, client, {}) + end + end +end diff --git a/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb new file mode 100644 index 00000000000..66dfc027e6e --- /dev/null +++ b/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Attachments::ImportMergeRequestWorker 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) + end + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + + it 'imports an merge request attachments' do + expect_next_instance_of( + Gitlab::GithubImport::Importer::NoteAttachmentsImporter, + an_instance_of(Gitlab::GithubImport::Representation::NoteText), + project, + client + ) do |note_attachments_importer| + expect(note_attachments_importer).to receive(:execute) + end + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import(project, client, {}) + end + end +end diff --git a/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb new file mode 100644 index 00000000000..7b60cdecca6 --- /dev/null +++ b/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Attachments::ImportNoteWorker 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) + end + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') } + + let(:note_hash) do + { + 'record_db_id' => rand(100), + 'record_type' => 'Note', + 'text' => <<-TEXT + Some text... + + ![special-image](https://user-images.githubusercontent.com...) + TEXT + } + end + + it 'imports an release attachments' do + expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter) + .to receive(:new) + .with( + an_instance_of(Gitlab::GithubImport::Representation::NoteText), + project, + client + ) + .and_return(importer) + + expect(importer).to receive(:execute) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import(project, client, note_hash) + end + end +end diff --git a/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb new file mode 100644 index 00000000000..e49b2fb6504 --- /dev/null +++ b/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Attachments::ImportReleaseWorker 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) + end + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') } + + let(:note_hash) do + { + 'record_db_id' => rand(100), + 'record_type' => 'Release', + 'text' => <<-TEXT + Some text... + + ![special-image](https://user-images.githubusercontent.com...) + TEXT + } + end + + it 'imports an release attachments' do + expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter) + .to receive(:new) + .with( + an_instance_of(Gitlab::GithubImport::Representation::NoteText), + project, + client + ) + .and_return(importer) + + expect(importer).to receive(:execute) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import(project, client, note_hash) + end + end +end diff --git a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb index c2a7639fde4..ef1d2e3f3e7 100644 --- a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb @@ -45,4 +45,15 @@ RSpec.describe Gitlab::GithubImport::ImportIssueWorker do worker.import(project, client, hash) end end + + describe '#increment_object_counter?' do + context 'when github issue is a pull request' do + let(:issue) { double(:issue, pull_request?: true) } + let(:project) { double(:project) } + + it 'returns false' do + expect(worker).not_to be_increment_object_counter(issue) + end + end + end end diff --git a/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb index cd53c6ee9c0..1d32d5c0e21 100644 --- a/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker do end let(:client) { instance_double('Gitlab::GithubImport::Client') } - let(:importer) { instance_double('Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') } let(:release_hash) do { @@ -27,10 +27,10 @@ RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker do end it 'imports an issue event' do - expect(Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter) + expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter) .to receive(:new) .with( - an_instance_of(Gitlab::GithubImport::Representation::ReleaseAttachments), + an_instance_of(Gitlab::GithubImport::Representation::NoteText), project, client ) 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 c2c5e1dbf4e..ecfece735af 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 @@ -5,40 +5,60 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker do subject(:worker) { described_class.new } - let(:project) { create(:project) } - let!(:group) { create(:group, projects: [project]) } - let(:feature_flag_state) { [group] } + let_it_be(:project) { create(:project) } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:stage_enabled) { true } + + before do + settings.write({ attachments_import: stage_enabled }) + end describe '#import' do - let(:importer) { instance_double('Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter') } let(:client) { instance_double('Gitlab::GithubImport::Client') } - - before do - stub_feature_flags(github_importer_attachments_import: feature_flag_state) + let(:importers) do + [ + { + klass: Gitlab::GithubImport::Importer::Attachments::ReleasesImporter, + double: instance_double('Gitlab::GithubImport::Importer::Attachments::ReleasesImporter'), + waiter: Gitlab::JobWaiter.new(2, '123') + }, + { + klass: Gitlab::GithubImport::Importer::Attachments::NotesImporter, + double: instance_double('Gitlab::GithubImport::Importer::Attachments::NotesImporter'), + waiter: Gitlab::JobWaiter.new(3, '234') + }, + { + klass: Gitlab::GithubImport::Importer::Attachments::IssuesImporter, + double: instance_double('Gitlab::GithubImport::Importer::Attachments::IssuesImporter'), + waiter: Gitlab::JobWaiter.new(4, '345') + }, + { + klass: Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter, + double: instance_double('Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter'), + waiter: Gitlab::JobWaiter.new(5, '456') + } + ] end - it 'imports release attachments' do - waiter = Gitlab::JobWaiter.new(2, '123') - - expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter) - .to receive(:new) - .with(project, client) - .and_return(importer) - - expect(importer).to receive(:execute).and_return(waiter) + it 'imports attachments' do + importers.each do |importer| + expect_next_instance_of(importer[:klass], project, client) do |instance| + expect(instance).to receive(:execute).and_return(importer[:waiter]) + end + end expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) - .with(project.id, { '123' => 2 }, :protected_branches) + .with(project.id, { '123' => 2, '234' => 3, '345' => 4, '456' => 5 }, :protected_branches) worker.import(client, project) end - context 'when feature flag is disabled' do - let(:feature_flag_state) { false } + context 'when stage is disabled' do + let(:stage_enabled) { false } it 'skips release attachments import and calls next stage' do - expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter).not_to receive(:new) + importers.each { |importer| expect(importer[:klass]).not_to receive(:new) } expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async).with(project.id, {}, :protected_branches) 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 932152c0764..199d1b9a3ca 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 @@ -7,23 +7,21 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker do let(:project) { create(:project) } let!(:group) { create(:group, projects: [project]) } - let(:feature_flag_state) { [group] } - let(:single_endpoint_feature_flag_state) { [group] } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:stage_enabled) { true } + + before do + settings.write({ single_endpoint_issue_events_import: stage_enabled }) + end describe '#import' do let(:importer) { instance_double('Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter') } let(:client) { instance_double('Gitlab::GithubImport::Client') } - before do - stub_feature_flags(github_importer_single_endpoint_issue_events_import: single_endpoint_feature_flag_state) - stub_feature_flags(github_importer_issue_events_import: feature_flag_state) - end - - context 'when single endpoint feature flag enabled' do - it 'imports all the issue events' do + context 'when stage is enabled' do + it 'imports issue events' do waiter = Gitlab::JobWaiter.new(2, '123') - expect(Gitlab::GithubImport::Importer::IssueEventsImporter).not_to receive(:new) expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter) .to receive(:new) .with(project, client) @@ -39,35 +37,11 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker do end end - context 'when import issue events feature flag enabled' do - let(:single_endpoint_feature_flag_state) { false } - - it 'imports the issue events partly' do - waiter = Gitlab::JobWaiter.new(2, '123') - - expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter).not_to receive(:new) - expect(Gitlab::GithubImport::Importer::IssueEventsImporter) - .to receive(:new) - .with(project, client) - .and_return(importer) - - expect(importer).to receive(:execute).and_return(waiter) - - expect(Gitlab::GithubImport::AdvanceStageWorker) - .to receive(:perform_async) - .with(project.id, { '123' => 2 }, :notes) - - worker.import(client, project) - end - end - - context 'when feature flags are disabled' do - let(:feature_flag_state) { false } - let(:single_endpoint_feature_flag_state) { false } + context 'when stage is disabled' do + let(:stage_enabled) { false } it 'skips issue events import and calls next stage' do expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter).not_to receive(:new) - expect(Gitlab::GithubImport::Importer::IssueEventsImporter).not_to receive(:new) expect(Gitlab::GithubImport::AdvanceStageWorker).to receive(:perform_async).with(project.id, {}, :notes) worker.import(client, project) 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 a88256b3cae..beef0864715 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 @@ -6,6 +6,13 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker do let(:project) { create(:project) } let(:worker) { described_class.new } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:single_endpoint_optional_stage) { true } + + before do + settings.write({ single_endpoint_notes_import: single_endpoint_optional_stage }) + end + describe '#import' do it 'imports the issues and diff notes' do client = double(:client) @@ -33,37 +40,18 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker do end describe '#importers' do - context 'when project group is present' do - let_it_be(:project) { create(:project) } - let_it_be(:group) { create(:group, projects: [project]) } - - context 'when feature flag github_importer_single_endpoint_notes_import is enabled' do - it 'includes single endpoint diff notes importer' do - project = create(:project) - group = create(:group, projects: [project]) - - stub_feature_flags(github_importer_single_endpoint_notes_import: group) - - expect(worker.importers(project)).to contain_exactly( - Gitlab::GithubImport::Importer::IssuesImporter, - Gitlab::GithubImport::Importer::SingleEndpointDiffNotesImporter - ) - end - end - - context 'when feature flag github_importer_single_endpoint_notes_import is disabled' do - it 'includes default diff notes importer' do - stub_feature_flags(github_importer_single_endpoint_notes_import: false) - - expect(worker.importers(project)).to contain_exactly( - Gitlab::GithubImport::Importer::IssuesImporter, - Gitlab::GithubImport::Importer::DiffNotesImporter - ) - end + context 'when optional stage single_endpoint_notes_import is enabled' do + it 'includes single endpoint diff notes importer' do + expect(worker.importers(project)).to contain_exactly( + Gitlab::GithubImport::Importer::IssuesImporter, + Gitlab::GithubImport::Importer::SingleEndpointDiffNotesImporter + ) end end - context 'when project group is missing' do + context 'when optional stage single_endpoint_notes_import is disabled' do + let(:single_endpoint_optional_stage) { false } + it 'includes default diff notes importer' do expect(worker.importers(project)).to contain_exactly( Gitlab::GithubImport::Importer::IssuesImporter, 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 adf20d24a7e..dbcf2083ec1 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 @@ -6,6 +6,13 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker do let(:project) { create(:project) } let(:worker) { described_class.new } + let(:settings) { ::Gitlab::GithubImport::Settings.new(project) } + let(:single_endpoint_optional_stage) { true } + + before do + settings.write({ single_endpoint_notes_import: single_endpoint_optional_stage }) + end + describe '#import' do it 'imports all the notes' do client = double(:client) @@ -33,37 +40,19 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker do end describe '#importers' do - context 'when project group is present' do - let_it_be(:project) { create(:project) } - let_it_be(:group) { create(:group, projects: [project]) } - - context 'when feature flag github_importer_single_endpoint_notes_import is enabled' do - it 'includes single endpoint mr and issue notes importers' do - project = create(:project) - group = create(:group, projects: [project]) - - stub_feature_flags(github_importer_single_endpoint_notes_import: group) - - expect(worker.importers(project)).to contain_exactly( - Gitlab::GithubImport::Importer::SingleEndpointMergeRequestNotesImporter, - Gitlab::GithubImport::Importer::SingleEndpointIssueNotesImporter - ) - end - end - - context 'when feature flag github_importer_single_endpoint_notes_import is disabled' do - it 'includes default notes importer' do - stub_feature_flags(github_importer_single_endpoint_notes_import: false) - - expect(worker.importers(project)).to contain_exactly( - Gitlab::GithubImport::Importer::NotesImporter - ) - end + context 'when settings single_endpoint_notes_import is enabled' do + it 'includes single endpoint mr and issue notes importers' do + expect(worker.importers(project)).to contain_exactly( + Gitlab::GithubImport::Importer::SingleEndpointMergeRequestNotesImporter, + Gitlab::GithubImport::Importer::SingleEndpointIssueNotesImporter + ) end end - context 'when project group is missing' do - it 'includes default diff notes importer' do + context 'when settings single_endpoint_notes_import is disabled' do + let(:single_endpoint_optional_stage) { false } + + it 'includes default notes importer' do expect(worker.importers(project)).to contain_exactly( Gitlab::GithubImport::Importer::NotesImporter ) 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 582cb76a6cd..24fca3b7c73 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 @@ -19,18 +19,69 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do end context 'when the import succeeds' do - it 'schedules the importing of the base data' do - client = double(:client) + context 'with issues' do + it 'schedules the importing of the base data' do + client = double(:client) + options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } - expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| - expect(instance).to receive(:execute).and_return(true) + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).with( + :issues, project.import_source, options + ).and_return([{ number: 5 }].each) + + expect(Issue).to receive(:track_project_iid!).with(project, 5) + + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) end + end - expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) - .to receive(:perform_async) - .with(project.id) + context 'without issues' do + it 'schedules the importing of the base data' do + client = double(:client) + options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } + + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).with(:issues, project.import_source, options).and_return([nil].each) + expect(Issue).not_to receive(:track_project_iid!) - worker.import(client, project) + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) + end + end + + context 'when retrying' do + it 'does not allocate internal ids' do + client = double(:client) + + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(true) + expect(client).not_to receive(:each_object) + expect(Issue).not_to receive(:track_project_iid!) + + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) + end end end @@ -43,6 +94,10 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(instance).to receive(:execute).and_raise(exception_class) end + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).and_return([nil].each) + expect(Issue).not_to receive(:track_project_iid!) + expect(Gitlab::Import::ImportFailureService).to receive(:track) .with( project_id: project.id, diff --git a/spec/workers/integrations/create_external_cross_reference_worker_spec.rb b/spec/workers/integrations/create_external_cross_reference_worker_spec.rb index 61723f44aa5..8e586b90905 100644 --- a/spec/workers/integrations/create_external_cross_reference_worker_spec.rb +++ b/spec/workers/integrations/create_external_cross_reference_worker_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Integrations::CreateExternalCrossReferenceWorker do include AfterNextHelpers using RSpec::Parameterized::TableSyntax - let_it_be(:project) { create(:jira_project, :repository) } + let_it_be(:project) { create(:project, :with_jira_integration, :repository) } let_it_be(:author) { create(:user) } let_it_be(:commit) { project.commit } let_it_be(:issue) { create(:issue, project: project) } diff --git a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb index 957adbbbd6e..fe677103fd0 100644 --- a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb +++ b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb @@ -53,6 +53,48 @@ RSpec.describe MergeRequests::DeleteSourceBranchWorker do worker.perform(merge_request.id, 'new-source-branch-sha', user.id) end end + + context 'when delete service returns an error' do + let(:service_result) { ServiceResponse.error(message: 'placeholder') } + + it 'tracks the exception' do + expect_next_instance_of(::Branches::DeleteService) do |instance| + expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result) + end + + expect(service_result).to receive(:track_exception).and_call_original + + worker.perform(merge_request.id, sha, user.id) + end + + context 'when track_delete_source_errors is disabled' do + before do + stub_feature_flags(track_delete_source_errors: false) + end + + it 'does not track the exception' do + expect_next_instance_of(::Branches::DeleteService) do |instance| + expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result) + end + + expect(service_result).not_to receive(:track_exception) + + worker.perform(merge_request.id, sha, user.id) + end + end + + it 'still retargets the merge request' do + expect_next_instance_of(::Branches::DeleteService) do |instance| + expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result) + end + + expect_next_instance_of(::MergeRequests::RetargetChainService) do |instance| + expect(instance).to receive(:execute).with(merge_request) + end + + worker.perform(merge_request.id, sha, user.id) + end + end end it_behaves_like 'an idempotent worker' do diff --git a/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb b/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb index 11f2501cbe3..d8c60932d92 100644 --- a/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb +++ b/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Namespaces::PruneAggregationSchedulesWorker, '#perform', :clean_g include ExclusiveLeaseHelpers let(:namespaces) { create_list(:namespace, 5, :with_aggregation_schedule) } - let(:timeout) { Namespace::AggregationSchedule::DEFAULT_LEASE_TIMEOUT } + let(:timeout) { Namespace::AggregationSchedule.default_lease_timeout } subject(:worker) { described_class.new } diff --git a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb b/spec/workers/onboarding/issue_created_worker_spec.rb index 0a896d864b7..70a0156d444 100644 --- a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb +++ b/spec/workers/onboarding/issue_created_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::OnboardingIssueCreatedWorker, '#perform' do +RSpec.describe Onboarding::IssueCreatedWorker, '#perform' do let_it_be(:issue) { create(:issue) } let(:namespace) { issue.project.namespace } diff --git a/spec/workers/namespaces/onboarding_pipeline_created_worker_spec.rb b/spec/workers/onboarding/pipeline_created_worker_spec.rb index 6d69ccb50bd..75bdea28eef 100644 --- a/spec/workers/namespaces/onboarding_pipeline_created_worker_spec.rb +++ b/spec/workers/onboarding/pipeline_created_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::OnboardingPipelineCreatedWorker, '#perform' do +RSpec.describe Onboarding::PipelineCreatedWorker, '#perform' do let_it_be(:ci_pipeline) { create(:ci_pipeline) } it_behaves_like 'records an onboarding progress action', :pipeline_created do diff --git a/spec/workers/namespaces/onboarding_progress_worker_spec.rb b/spec/workers/onboarding/progress_worker_spec.rb index 76ac078ddcf..bbf4875069e 100644 --- a/spec/workers/namespaces/onboarding_progress_worker_spec.rb +++ b/spec/workers/onboarding/progress_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::OnboardingProgressWorker, '#perform' do +RSpec.describe Onboarding::ProgressWorker, '#perform' do let_it_be(:namespace) { create(:namespace) } let_it_be(:action) { 'git_pull' } diff --git a/spec/workers/namespaces/onboarding_user_added_worker_spec.rb b/spec/workers/onboarding/user_added_worker_spec.rb index 14428c0ecb8..6dbd875c93b 100644 --- a/spec/workers/namespaces/onboarding_user_added_worker_spec.rb +++ b/spec/workers/onboarding/user_added_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::OnboardingUserAddedWorker, '#perform' do +RSpec.describe Onboarding::UserAddedWorker, '#perform' do let_it_be(:namespace) { create(:group) } subject { described_class.new.perform(namespace.id) } diff --git a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb index 9272e26a34f..b9c27c54fa1 100644 --- a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb +++ b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb @@ -126,6 +126,107 @@ RSpec.describe Pages::InvalidateDomainCacheWorker do { type: :namespace, id: 3 } ] + it_behaves_like 'clears caches with', + event_class: PagesDomains::PagesDomainDeletedEvent, + event_data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + domain: 'somedomain.com' + }, + caches: [ + { type: :project, id: 1 }, + { type: :namespace, id: 3 } + ] + + it_behaves_like 'clears caches with', + event_class: PagesDomains::PagesDomainUpdatedEvent, + event_data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + domain: 'somedomain.com' + }, + caches: [ + { type: :project, id: 1 }, + { type: :namespace, id: 3 } + ] + + it_behaves_like 'clears caches with', + event_class: PagesDomains::PagesDomainCreatedEvent, + event_data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + domain: 'somedomain.com' + }, + caches: [ + { type: :project, id: 1 }, + { type: :namespace, id: 3 } + ] + + context 'when project attributes change' do + Projects::ProjectAttributesChangedEvent::PAGES_RELATED_ATTRIBUTES.each do |attribute| + it_behaves_like 'clears caches with', + event_class: Projects::ProjectAttributesChangedEvent, + event_data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + attributes: [attribute] + }, + caches: [ + { type: :project, id: 1 }, + { type: :namespace, id: 3 } + ] + end + + it 'does not clear the cache when the attributes is not pages related' do + event = Projects::ProjectAttributesChangedEvent.new( + data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + attributes: ['unknown'] + } + ) + + expect(described_class).not_to receive(:clear_cache) + + ::Gitlab::EventStore.publish(event) + end + end + + context 'when project features change' do + it_behaves_like 'clears caches with', + event_class: Projects::ProjectFeaturesChangedEvent, + event_data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + features: ["pages_access_level"] + }, + caches: [ + { type: :project, id: 1 }, + { type: :namespace, id: 3 } + ] + + it 'does not clear the cache when the features is not pages related' do + event = Projects::ProjectFeaturesChangedEvent.new( + data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3, + features: ['unknown'] + } + ) + + expect(described_class).not_to receive(:clear_cache) + + ::Gitlab::EventStore.publish(event) + end + end + context 'when namespace based cache keys are duplicated' do # de-dups namespace cache keys it_behaves_like 'clears caches with', diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index a445db3a276..01c44399b0c 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -120,34 +120,6 @@ RSpec.describe ProcessCommitWorker do worker.close_issues(project, user, user, commit, [issue]) end.to change(Issues::CloseWorker.jobs, :size).by(1) end - - context 'when process_issue_closure_in_background flag is disabled' do - before do - stub_feature_flags(process_issue_closure_in_background: false) - end - - context 'when the user can update the issues' do - it 'closes the issues' do - worker.close_issues(project, user, user, commit, [issue]) - - issue.reload - - expect(issue.closed?).to eq(true) - end - end - - context 'when the user can not update the issues' do - it 'does not close the issues' do - other_user = create(:user) - - worker.close_issues(project, other_user, other_user, commit, [issue]) - - issue.reload - - expect(issue.closed?).to eq(false) - end - end - end end describe '#update_issue_metrics', :clean_gitlab_redis_cache do diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb index 30c85464452..3c807ef9ffd 100644 --- a/spec/workers/project_cache_worker_spec.rb +++ b/spec/workers/project_cache_worker_spec.rb @@ -39,7 +39,7 @@ RSpec.describe ProjectCacheWorker do context 'with an existing project' do before do lease_key = "namespace:namespaces_root_statistics:#{project.namespace_id}" - stub_exclusive_lease_taken(lease_key, timeout: Namespace::AggregationSchedule::DEFAULT_LEASE_TIMEOUT) + stub_exclusive_lease_taken(lease_key, timeout: Namespace::AggregationSchedule.default_lease_timeout) end it 'refreshes the method caches' do @@ -74,8 +74,8 @@ RSpec.describe ProjectCacheWorker do context 'with plain readme' do it 'refreshes the method caches' do - allow(MarkupHelper).to receive(:gitlab_markdown?).and_return(false) - allow(MarkupHelper).to receive(:plain?).and_return(true) + allow(Gitlab::MarkupHelper).to receive(:gitlab_markdown?).and_return(false) + allow(Gitlab::MarkupHelper).to receive(:plain?).and_return(true) expect_any_instance_of(Repository).to receive(:refresh_method_caches) .with(%i(readme)) diff --git a/spec/workers/project_destroy_worker_spec.rb b/spec/workers/project_destroy_worker_spec.rb index 0b0543a5089..25508928bbf 100644 --- a/spec/workers/project_destroy_worker_spec.rb +++ b/spec/workers/project_destroy_worker_spec.rb @@ -4,11 +4,7 @@ require 'spec_helper' RSpec.describe ProjectDestroyWorker do let(:project) { create(:project, :repository, pending_delete: true) } - let(:path) do - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - project.repository.path_to_repo - end - end + let!(:repository) { project.repository.raw } subject { described_class.new } @@ -17,7 +13,7 @@ RSpec.describe ProjectDestroyWorker do subject.perform(project.id, project.first_owner.id, {}) expect(Project.all).not_to include(project) - expect(Dir.exist?(path)).to be_falsey + expect(repository).not_to exist end it 'does not raise error when project could not be found' do diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 205d7c08f54..dbb24cc047e 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -68,7 +68,7 @@ RSpec.describe RepositoryCheck::SingleRepositoryWorker do it 'creates missing wikis' do project = create(:project, :wiki_enabled) - TestEnv.rm_storage_dir(project.repository_storage, project.wiki.path) + project.wiki.repository.raw.remove subject.perform(project.id) @@ -77,8 +77,8 @@ RSpec.describe RepositoryCheck::SingleRepositoryWorker do it 'does not create a wiki if the main repo does not exist at all' do project = create(:project, :repository) - TestEnv.rm_storage_dir(project.repository_storage, project.path) - TestEnv.rm_storage_dir(project.repository_storage, project.wiki.path) + project.repository.raw.remove + project.wiki.repository.raw.remove subject.perform(project.id) diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb index 9c46b1e2a87..85dee935001 100644 --- a/spec/workers/repository_fork_worker_spec.rb +++ b/spec/workers/repository_fork_worker_spec.rb @@ -115,7 +115,7 @@ RSpec.describe RepositoryForkWorker do context 'project ID, storage and repo paths passed' do def perform! - subject.perform(forked_project.id, TestEnv.repos_path, project.disk_path) + subject.perform(forked_project.id, 'repos/path', project.disk_path) end it_behaves_like 'RepositoryForkWorker performing' diff --git a/spec/workers/run_pipeline_schedule_worker_spec.rb b/spec/workers/run_pipeline_schedule_worker_spec.rb index 846b4455bf9..10c22b736d2 100644 --- a/spec/workers/run_pipeline_schedule_worker_spec.rb +++ b/spec/workers/run_pipeline_schedule_worker_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' RSpec.describe RunPipelineScheduleWorker do describe '#perform' do - let_it_be(:project) { create(:project) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } let_it_be(:user) { create(:user) } let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } |