diff options
Diffstat (limited to 'spec/workers/stuck_ci_jobs_worker_spec.rb')
-rw-r--r-- | spec/workers/stuck_ci_jobs_worker_spec.rb | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/spec/workers/stuck_ci_jobs_worker_spec.rb b/spec/workers/stuck_ci_jobs_worker_spec.rb index e0a5d3c6c1c..19ff8ec55c2 100644 --- a/spec/workers/stuck_ci_jobs_worker_spec.rb +++ b/spec/workers/stuck_ci_jobs_worker_spec.rb @@ -5,50 +5,34 @@ require 'spec_helper' RSpec.describe StuckCiJobsWorker do include ExclusiveLeaseHelpers - let(:worker_lease_key) { StuckCiJobsWorker::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 - it 'executes an instance of Ci::StuckBuildsDropService' do - expect_next_instance_of(Ci::StuckBuilds::DropService) do |service| - expect(service).to receive(:execute).exactly(:once) - end - - worker.perform - end + subject { worker.perform } - 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) + it 'enqueues a Ci::StuckBuilds::DropRunningWorker job' do + expect(Ci::StuckBuilds::DropRunningWorker).to receive(:perform_in).with(20.minutes).exactly(:once) - worker.perform + subject + end - stub_exclusive_lease_taken(worker_lease_key) + it 'enqueues a Ci::StuckBuilds::DropScheduledWorker job' do + expect(Ci::StuckBuilds::DropScheduledWorker).to receive(:perform_in).with(40.minutes).exactly(:once) - worker2.perform - end + subject + 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) + it 'executes an instance of Ci::StuckBuilds::DropPendingService' do + expect_to_obtain_exclusive_lease(worker.lease_key, lease_uuid) - worker.perform - worker2.perform + expect_next_instance_of(Ci::StuckBuilds::DropPendingService) do |service| + expect(service).to receive(:execute).exactly(:once) 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 + subject end end end |