diff options
author | Nick Thomas <nick@gitlab.com> | 2017-11-28 12:46:39 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-11-28 12:46:39 +0000 |
commit | 0185d7800b23daecd44abe8e9a0b2672a831e8be (patch) | |
tree | af69f53cbc9842246dd5c67f0985aaea69cbc40a /spec/workers | |
parent | 85ff313a1ecf3fc0ffbf1989533d4fa38bd8daf8 (diff) | |
parent | 58f32622ce9c2d08001da7b91065942cdc5a0f4a (diff) | |
download | gitlab-ce-0185d7800b23daecd44abe8e9a0b2672a831e8be.tar.gz |
Merge branch 'hashed-storage-attachments-migration-path' into 'master'
Hashed storage attachments migration path
See merge request gitlab-org/gitlab-ce!15352
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/project_migrate_hashed_storage_worker_spec.rb | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/spec/workers/project_migrate_hashed_storage_worker_spec.rb b/spec/workers/project_migrate_hashed_storage_worker_spec.rb index f5226dee0ad..2e3951e7afc 100644 --- a/spec/workers/project_migrate_hashed_storage_worker_spec.rb +++ b/spec/workers/project_migrate_hashed_storage_worker_spec.rb @@ -1,29 +1,53 @@ require 'spec_helper' -describe ProjectMigrateHashedStorageWorker do +describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do describe '#perform' do let(:project) { create(:project, :empty_repo) } let(:pending_delete_project) { create(:project, :empty_repo, pending_delete: true) } - it 'skips when project no longer exists' do - nonexistent_id = 999999999999 + context 'when have exclusive lease' do + before do + lease = subject.lease_for(project.id) - expect(::Projects::HashedStorageMigrationService).not_to receive(:new) - subject.perform(nonexistent_id) - end + allow(Gitlab::ExclusiveLease).to receive(:new).and_return(lease) + allow(lease).to receive(:try_obtain).and_return(true) + end + + it 'skips when project no longer exists' do + nonexistent_id = 999999999999 + + expect(::Projects::HashedStorageMigrationService).not_to receive(:new) + subject.perform(nonexistent_id) + end + + it 'skips when project is pending delete' do + expect(::Projects::HashedStorageMigrationService).not_to receive(:new) - it 'skips when project is pending delete' do - expect(::Projects::HashedStorageMigrationService).not_to receive(:new) + subject.perform(pending_delete_project.id) + end - subject.perform(pending_delete_project.id) + it 'delegates removal to service class' do + service = double('service') + expect(::Projects::HashedStorageMigrationService).to receive(:new).with(project, subject.logger).and_return(service) + expect(service).to receive(:execute) + + subject.perform(project.id) + end end - it 'delegates removal to service class' do - service = double('service') - expect(::Projects::HashedStorageMigrationService).to receive(:new).with(project, subject.logger).and_return(service) - expect(service).to receive(:execute) + context 'when dont have exclusive lease' do + before do + lease = subject.lease_for(project.id) + + allow(Gitlab::ExclusiveLease).to receive(:new).and_return(lease) + allow(lease).to receive(:try_obtain).and_return(false) + end + + it 'skips when dont have lease' do + expect(::Projects::HashedStorageMigrationService).not_to receive(:new) - subject.perform(project.id) + subject.perform(project.id) + end end end end |