2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-07 13:00:46 +00:00
|
|
|
require 'spec_helper'
|
2015-10-21 09:29:47 +00:00
|
|
|
|
2020-06-26 09:08:59 +00:00
|
|
|
RSpec.describe StuckCiJobsWorker do
|
2018-06-28 18:51:36 +00:00
|
|
|
include ExclusiveLeaseHelpers
|
|
|
|
|
2021-10-07 12:12:09 +00:00
|
|
|
let(:worker) { described_class.new }
|
|
|
|
let(:lease_uuid) { SecureRandom.uuid }
|
2017-02-07 13:00:46 +00:00
|
|
|
|
2021-09-13 18:11:46 +00:00
|
|
|
describe '#perform' do
|
2021-10-07 12:12:09 +00:00
|
|
|
subject { worker.perform }
|
|
|
|
|
2021-09-29 21:12:32 +00:00
|
|
|
it 'enqueues a Ci::StuckBuilds::DropRunningWorker job' do
|
|
|
|
expect(Ci::StuckBuilds::DropRunningWorker).to receive(:perform_in).with(20.minutes).exactly(:once)
|
|
|
|
|
2021-10-07 12:12:09 +00:00
|
|
|
subject
|
2021-09-29 21:12:32 +00:00
|
|
|
end
|
|
|
|
|
2021-10-05 00:12:25 +00:00
|
|
|
it 'enqueues a Ci::StuckBuilds::DropScheduledWorker job' do
|
|
|
|
expect(Ci::StuckBuilds::DropScheduledWorker).to receive(:perform_in).with(40.minutes).exactly(:once)
|
|
|
|
|
2021-10-07 12:12:09 +00:00
|
|
|
subject
|
2021-10-05 00:12:25 +00:00
|
|
|
end
|
|
|
|
|
2021-10-08 12:11:10 +00:00
|
|
|
it 'executes an instance of Ci::StuckBuilds::DropPendingService' do
|
2021-10-07 12:12:09 +00:00
|
|
|
expect_to_obtain_exclusive_lease(worker.lease_key, lease_uuid)
|
|
|
|
|
2021-10-08 12:11:10 +00:00
|
|
|
expect_next_instance_of(Ci::StuckBuilds::DropPendingService) do |service|
|
2021-09-13 18:11:46 +00:00
|
|
|
expect(service).to receive(:execute).exactly(:once)
|
2019-11-01 00:06:02 +00:00
|
|
|
end
|
2017-02-07 13:00:46 +00:00
|
|
|
|
2021-10-07 12:12:09 +00:00
|
|
|
expect_to_cancel_exclusive_lease(worker.lease_key, lease_uuid)
|
2018-09-27 09:17:43 +00:00
|
|
|
|
2021-10-07 12:12:09 +00:00
|
|
|
subject
|
2018-09-27 09:17:43 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-01 12:56:54 +00:00
|
|
|
end
|