diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 15:12:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 15:12:09 +0300 |
commit | 43c3400c67f6470d4a19f143008990ee142dd828 (patch) | |
tree | 2268d48d59023e8353c6ab55290e8031e224dacc /spec/workers/ci | |
parent | bc935f05bc8d7dd89c3e7c88f90264e90b636e07 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/ci')
-rw-r--r-- | spec/workers/ci/stuck_builds/drop_running_worker_spec.rb | 58 |
1 files changed, 8 insertions, 50 deletions
diff --git a/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb b/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb index 9837902c449..6d3aa71fe81 100644 --- a/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb +++ b/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb @@ -5,66 +5,24 @@ require 'spec_helper' RSpec.describe Ci::StuckBuilds::DropRunningWorker do include ExclusiveLeaseHelpers - let(:worker_lease_key) { Ci::StuckBuilds::DropRunningWorker::EXCLUSIVE_LEASE_KEY } - let(:worker_lease_uuid) { SecureRandom.uuid } - let(:worker2) { described_class.new } - - subject(:worker) { described_class.new } - - before do - stub_exclusive_lease(worker_lease_key, worker_lease_uuid) - end + let(:worker) { described_class.new } + let(:lease_uuid) { SecureRandom.uuid } describe '#perform' do + subject { worker.perform } + it_behaves_like 'an idempotent worker' it 'executes an instance of Ci::StuckBuilds::DropRunningService' do + expect_to_obtain_exclusive_lease(worker.lease_key, lease_uuid) + expect_next_instance_of(Ci::StuckBuilds::DropRunningService) do |service| expect(service).to receive(:execute).exactly(:once) end - worker.perform - end - - context 'with an exclusive lease' do - it 'does not execute concurrently' do - expect(worker).to receive(:remove_lease).exactly(:once) - expect(worker2).not_to receive(:remove_lease) - - worker.perform - - stub_exclusive_lease_taken(worker_lease_key) - - worker2.perform - end - - it 'can execute in sequence' do - expect(worker).to receive(:remove_lease).at_least(:once) - expect(worker2).to receive(:remove_lease).at_least(:once) - - worker.perform - worker2.perform - end - - it 'cancels exclusive leases after worker perform' do - expect_to_cancel_exclusive_lease(worker_lease_key, worker_lease_uuid) + expect_to_cancel_exclusive_lease(worker.lease_key, lease_uuid) - worker.perform - end - - context 'when the DropRunningService fails' do - it 'ensures cancellation of the exclusive lease' do - expect_to_cancel_exclusive_lease(worker_lease_key, worker_lease_uuid) - - allow_next_instance_of(Ci::StuckBuilds::DropRunningService) do |service| - expect(service).to receive(:execute) do - raise 'The query timed out' - end - end - - expect { worker.perform }.to raise_error(/The query timed out/) - end - end + subject end end end |