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

click_house_migration_spec.rb « strategies « 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: 470c860fb605acc63445abaa76357a1f0193863d (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SidekiqMiddleware::PauseControl::Strategies::ClickHouseMigration, feature_category: :database do
  let(:worker_class) do
    Class.new do
      def self.name
        'TestPauseWorker'
      end

      include ::ApplicationWorker
      include ::ClickHouseWorker

      def perform(*); end
    end
  end

  before do
    stub_const('TestPauseWorker', worker_class)
  end

  describe '#call' do
    include Gitlab::ExclusiveLeaseHelpers

    shared_examples 'a worker being executed' do
      it 'schedules the job' do
        expect(Gitlab::SidekiqMiddleware::PauseControl::PauseControlService).not_to receive(:add_to_waiting_queue!)

        worker_class.perform_async('args1')

        expect(worker_class.jobs.count).to eq(1)
      end
    end

    context 'when lock is not taken' do
      it_behaves_like 'a worker being executed'
    end

    context 'when lock is taken' do
      include ExclusiveLeaseHelpers

      around do |example|
        ClickHouse::MigrationSupport::ExclusiveLock.execute_migration do
          example.run
        end
      end

      it 'does not schedule the job' do
        expect(Gitlab::SidekiqMiddleware::PauseControl::PauseControlService).to receive(:add_to_waiting_queue!).once

        worker_class.perform_async('args1')

        expect(worker_class.jobs.count).to eq(0)
      end

      context 'when pause_clickhouse_workers_during_migration FF is disabled' do
        before do
          stub_feature_flags(pause_clickhouse_workers_during_migration: false)
        end

        it_behaves_like 'a worker being executed'
      end
    end
  end
end