Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strategy_handler_spec.rb « pause_control « sidekiq_middleware « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: da53abec479c26b4ba3834e4627a20899f0098ee (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SidekiqMiddleware::PauseControl::StrategyHandler, :clean_gitlab_redis_queues, feature_category: :global_search do
  subject(:pause_control) do
    described_class.new(TestPauseWorker, job)
  end

  let(:worker_class) do
    Class.new do
      def self.name
        'TestPauseWorker'
      end

      include ApplicationWorker

      pause_control :zoekt

      def perform(*); end
    end
  end

  let(:job) { { 'class' => 'TestPauseWorker', 'args' => [1], 'jid' => '123' } }

  before do
    stub_const('TestPauseWorker', worker_class)
  end

  describe '#schedule' do
    shared_examples 'scheduling with pause control class' do |strategy_class|
      it 'calls schedule on the strategy' do
        expect do |block|
          klass = "Gitlab::SidekiqMiddleware::PauseControl::Strategies::#{strategy_class}".constantize
          expect_next_instance_of(klass) do |strategy|
            expect(strategy).to receive(:schedule).with(job, &block)
          end

          pause_control.schedule(&block)
        end.to yield_control
      end
    end

    it_behaves_like 'scheduling with pause control class', 'Zoekt'
  end

  describe '#perform' do
    it 'calls perform on the strategy' do
      expect do |block|
        expect_next_instance_of(Gitlab::SidekiqMiddleware::PauseControl::Strategies::Zoekt) do |strategy|
          expect(strategy).to receive(:perform).with(job, &block)
        end

        pause_control.perform(&block)
      end.to yield_control
    end

    it 'pauses job' do
      expect_next_instance_of(Gitlab::SidekiqMiddleware::PauseControl::Strategies::Zoekt) do |strategy|
        expect(strategy).to receive(:should_pause?).and_return(true)
      end

      expect { pause_control.perform }.to change {
        Gitlab::SidekiqMiddleware::PauseControl::PauseControlService.queue_size('TestPauseWorker')
      }.by(1)
    end
  end
end