diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 06:08:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 06:08:02 +0300 |
commit | ed73d4f207ef6cb8646719baa1188d096c9f3139 (patch) | |
tree | dea7ab9906154c73204a0361163e30500f929d44 /spec/workers | |
parent | 2349eabc1a473bfb70555f0ce6d3d808cecb181d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/hashed_storage/project_migrate_worker_spec.rb | 69 |
1 files changed, 52 insertions, 17 deletions
diff --git a/spec/workers/hashed_storage/project_migrate_worker_spec.rb b/spec/workers/hashed_storage/project_migrate_worker_spec.rb index f266c7dbe8c..4b1b5f84fd3 100644 --- a/spec/workers/hashed_storage/project_migrate_worker_spec.rb +++ b/spec/workers/hashed_storage/project_migrate_worker_spec.rb @@ -5,13 +5,13 @@ require 'spec_helper' describe HashedStorage::ProjectMigrateWorker, :clean_gitlab_redis_shared_state do include ExclusiveLeaseHelpers - describe '#perform' do - let(:project) { create(:project, :empty_repo, :legacy_storage) } - let(:lease_key) { "project_migrate_hashed_storage_worker:#{project.id}" } - let(:lease_timeout) { described_class::LEASE_TIMEOUT } - let(:migration_service) { ::Projects::HashedStorage::MigrationService } + let(:migration_service) { ::Projects::HashedStorage::MigrationService } + let(:lease_timeout) { described_class::LEASE_TIMEOUT } + describe '#perform' do it 'skips when project no longer exists' do + stub_exclusive_lease(lease_key(-1), 'uuid', timeout: lease_timeout) + expect(migration_service).not_to receive(:new) subject.perform(-1) @@ -19,32 +19,67 @@ describe HashedStorage::ProjectMigrateWorker, :clean_gitlab_redis_shared_state d it 'skips when project is pending delete' do pending_delete_project = create(:project, :empty_repo, pending_delete: true) + stub_exclusive_lease(lease_key(pending_delete_project.id), 'uuid', timeout: lease_timeout) expect(migration_service).not_to receive(:new) subject.perform(pending_delete_project.id) end - it 'delegates migration to service class when we have exclusive lease' do - stub_exclusive_lease(lease_key, 'uuid', timeout: lease_timeout) + it 'skips when project is already migrated' do + migrated_project = create(:project, :empty_repo) + stub_exclusive_lease(lease_key(migrated_project.id), 'uuid', timeout: lease_timeout) + + expect(migration_service).not_to receive(:new) + + subject.perform(migrated_project.id) + end + + context 'with exclusive lease available' do + it 'delegates migration to service class' do + project = create(:project, :empty_repo, :legacy_storage) + stub_exclusive_lease(lease_key(project.id), 'uuid', timeout: lease_timeout) - service_spy = spy + service_spy = spy - allow(migration_service) - .to receive(:new).with(project, project.full_path, logger: subject.logger) - .and_return(service_spy) + allow(migration_service) + .to receive(:new).with(project, project.full_path, logger: subject.logger) + .and_return(service_spy) - subject.perform(project.id) + subject.perform(project.id) - expect(service_spy).to have_received(:execute) + expect(service_spy).to have_received(:execute) + end + + it 'delegates migration to service class with correct path in a partially migrated project' do + project = create(:project, :empty_repo, storage_version: 1) + stub_exclusive_lease(lease_key(project.id), 'uuid', timeout: lease_timeout) + + service_spy = spy + + allow(migration_service) + .to receive(:new).with(project, project.full_path, logger: subject.logger) + .and_return(service_spy) + + subject.perform(project.id) + + expect(service_spy).to have_received(:execute) + end end - it 'skips when it cant acquire the exclusive lease' do - stub_exclusive_lease_taken(lease_key, timeout: lease_timeout) + context 'with exclusive lease taken' do + it 'skips when it cant acquire the exclusive lease' do + project = create(:project, :empty_repo, :legacy_storage) + stub_exclusive_lease_taken(lease_key(project.id), timeout: lease_timeout) - expect(migration_service).not_to receive(:new) + expect(migration_service).not_to receive(:new) - subject.perform(project.id) + subject.perform(project.id) + end end end + + def lease_key(key) + "project_migrate_hashed_storage_worker:#{key}" + end end |