Commit 9280583d authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'ensure-stuck-builds-lease-cancel' into 'master'

Ensure lease cancellation in StuckCiJobsWorker

See merge request gitlab-org/gitlab!71519
parents 9e76a6f8 5f2b8d0d
......@@ -21,9 +21,11 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
return unless try_obtain_lease
Ci::StuckBuilds::DropService.new.execute
remove_lease
begin
Ci::StuckBuilds::DropService.new.execute
ensure
remove_lease
end
end
private
......
......@@ -57,7 +57,7 @@ RSpec.describe Ci::StuckBuilds::DropRunningWorker do
expect_to_cancel_exclusive_lease(worker_lease_key, worker_lease_uuid)
allow_next_instance_of(Ci::StuckBuilds::DropRunningService) do |service|
allow(service).to receive(:execute) do
expect(service).to receive(:execute) do
raise 'The query timed out'
end
end
......
......@@ -55,6 +55,20 @@ RSpec.describe StuckCiJobsWorker do
worker.perform
end
context 'when the DropService 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::DropService) 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
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment