diff --git a/ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb b/ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb index ba7f2f828dde6d4bb60645c80aefa5f2e0ebc527..8b2f8738a0d6ea70c27a628d7669c6109f91423e 100644 --- a/ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb +++ b/ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb @@ -38,6 +38,40 @@ shared_examples "migrates" do |to_store:, from_store: nil| expect(File.exist?(original_file)).to be_falsey end + it 'can access to the original file during migration' do + original_file = subject.file.path + + allow(subject).to receive(:delete_migrated_file) { } + + expect { migrate(to) }.not_to change { File.exist?(original_file) } + end + + context 'when migrate! is not oqqupied by another process' do + it 'executes migrate!' do + expect(subject).to receive(:object_store=) + + migrate(to) + end + end + + context 'when migrate! is oqqupied by another process' do + let(:exclusive_lease_key) { "object_storage_migrate:#{subject.store_path}" } + + before do + @uuid = Gitlab::ExclusiveLease.new(exclusive_lease_key, timeout: 1.hour.to_i).try_obtain + end + + it 'does not execute migrate!' do + expect(subject).not_to receive(:object_store=) + + migrate(to) + end + + after do + Gitlab::ExclusiveLease.cancel(exclusive_lease_key, @uuid) + end + end + context 'migration is unsuccessful' do shared_examples "handles gracefully" do |error:| it 'does not update the object_store' do diff --git a/spec/uploaders/job_artifact_uploader_spec.rb b/spec/uploaders/job_artifact_uploader_spec.rb index 0bcf28f2c1c824eb983644425f367a574585ba97..714b24985382c358697e69c9b91cfce4116d80ae 100644 --- a/spec/uploaders/job_artifact_uploader_spec.rb +++ b/spec/uploaders/job_artifact_uploader_spec.rb @@ -67,4 +67,14 @@ describe JobArtifactUploader do it { is_expected.to include("/#{job_artifact.job_id}/#{job_artifact.id}/") } it { is_expected.to end_with("ci_build_artifacts.zip") } end + + describe "#migrate!" do + before do + uploader.store!(fixture_file_upload(Rails.root.join('spec/fixtures/trace/sample_trace'))) + stub_artifacts_object_storage + end + + it_behaves_like "migrates", to_store: described_class::Store::REMOTE + it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL + end end