diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2019-01-23 05:31:57 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2019-03-01 17:49:20 +0300 |
commit | d63380fa93dff921c69f7aaa31ff004864e4db13 (patch) | |
tree | 5473628a284c200222fddc9c1e7775e691c763bc /spec/workers/hashed_storage | |
parent | 1592b5830f7b2847dff02ef2c66b745cdc60565a (diff) |
Refactor ProjectMigrate and ProjectRollback workers
Moved to HashedStorage namespace, and added them to the
`:hashed_storage` queue namespace
Diffstat (limited to 'spec/workers/hashed_storage')
-rw-r--r-- | spec/workers/hashed_storage/project_migrate_worker_spec.rb | 48 | ||||
-rw-r--r-- | spec/workers/hashed_storage/project_rollback_worker_spec.rb | 50 |
2 files changed, 98 insertions, 0 deletions
diff --git a/spec/workers/hashed_storage/project_migrate_worker_spec.rb b/spec/workers/hashed_storage/project_migrate_worker_spec.rb new file mode 100644 index 00000000000..340e722aa7e --- /dev/null +++ b/spec/workers/hashed_storage/project_migrate_worker_spec.rb @@ -0,0 +1,48 @@ +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 } + + it 'skips when project no longer exists' do + expect(migration_service).not_to receive(:new) + + subject.perform(-1) + end + + it 'skips when project is pending delete' do + pending_delete_project = create(:project, :empty_repo, pending_delete: true) + + 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) + + 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 + + it 'skips when it cant acquire the exclusive lease' do + stub_exclusive_lease_taken(lease_key, timeout: lease_timeout) + + expect(migration_service).not_to receive(:new) + + subject.perform(project.id) + end + end +end diff --git a/spec/workers/hashed_storage/project_rollback_worker_spec.rb b/spec/workers/hashed_storage/project_rollback_worker_spec.rb new file mode 100644 index 00000000000..d833553c0ec --- /dev/null +++ b/spec/workers/hashed_storage/project_rollback_worker_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe HashedStorage::ProjectRollbackWorker, :clean_gitlab_redis_shared_state do + include ExclusiveLeaseHelpers + + describe '#perform' do + let(:project) { create(:project, :empty_repo) } + let(:lease_key) { "project_migrate_hashed_storage_worker:#{project.id}" } + let(:lease_timeout) { described_class::LEASE_TIMEOUT } + let(:rollback_service) { ::Projects::HashedStorage::RollbackService } + + it 'skips when project no longer exists' do + expect(rollback_service).not_to receive(:new) + + subject.perform(-1) + end + + it 'skips when project is pending delete' do + pending_delete_project = create(:project, :empty_repo, pending_delete: true) + + expect(rollback_service).not_to receive(:new) + + subject.perform(pending_delete_project.id) + end + + it 'delegates rollback to service class when have exclusive lease' do + stub_exclusive_lease(lease_key, 'uuid', timeout: lease_timeout) + + service_spy = spy + + allow(rollback_service) + .to receive(:new).with(project, project.disk_path, logger: subject.logger) + .and_return(service_spy) + + subject.perform(project.id) + + expect(service_spy).to have_received(:execute) + end + + it 'skips when it cant acquire the exclusive lease' do + stub_exclusive_lease_taken(lease_key, timeout: lease_timeout) + + expect(rollback_service).not_to receive(:new) + + subject.perform(project.id) + end + end +end |