summaryrefslogtreecommitdiff
path: root/spec/workers/schedule_merge_request_cleanup_refs_worker_spec.rb
blob: 869818b257ec992e16416f5f9f5abd30a3e6d865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ScheduleMergeRequestCleanupRefsWorker do
  subject(:worker) { described_class.new }

  describe '#perform' do
    before do
      allow(MergeRequest::CleanupSchedule)
        .to receive(:scheduled_merge_request_ids)
        .with(described_class::LIMIT)
        .and_return([1, 2, 3, 4])
    end

    it 'does nothing if the database is read-only' do
      allow(Gitlab::Database).to receive(:read_only?).and_return(true)
      expect(MergeRequestCleanupRefsWorker).not_to receive(:bulk_perform_in)

      worker.perform
    end

    context 'when merge_request_refs_cleanup flag is disabled' do
      before do
        stub_feature_flags(merge_request_refs_cleanup: false)
      end

      it 'does not schedule any merge request clean ups' do
        expect(MergeRequestCleanupRefsWorker).not_to receive(:bulk_perform_in)

        worker.perform
      end
    end

    include_examples 'an idempotent worker' do
      it 'schedules MergeRequestCleanupRefsWorker to be performed by batch' do
        expect(MergeRequestCleanupRefsWorker)
          .to receive(:bulk_perform_in)
          .with(
            described_class::DELAY,
            [[1], [2], [3], [4]],
            batch_size: described_class::BATCH_SIZE
          )

        expect(worker).to receive(:log_extra_metadata_on_done).with(:merge_requests_count, 4)

        worker.perform
      end
    end
  end
end