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

write_ahead_log_spec.rb « indicators « health_status « background_migration « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 650f11e3cd58dd204dbe50000dc6dcc4e3304010 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::BackgroundMigration::HealthStatus::Indicators::WriteAheadLog do
  let(:connection) { Gitlab::Database.database_base_models[:main].connection }

  around do |example|
    Gitlab::Database::SharedModel.using_connection(connection) do
      example.run
    end
  end

  describe '#evaluate' do
    let(:tables) { [table] }
    let(:table) { 'users' }
    let(:context) { Gitlab::Database::BackgroundMigration::HealthStatus::Context.new(connection, tables) }

    subject(:evaluate) { described_class.new(context).evaluate }

    it 'remembers the indicator class' do
      expect(evaluate.indicator_class).to eq(described_class)
    end

    it 'returns NoSignal signal in case the feature flag is disabled' do
      stub_feature_flags(batched_migrations_health_status_wal: false)

      expect(evaluate).to be_a(Gitlab::Database::BackgroundMigration::HealthStatus::Signals::NotAvailable)
      expect(evaluate.reason).to include('indicator disabled')
    end

    it 'returns NoSignal signal when WAL archive queue can not be calculated' do
      expect(connection).to receive(:execute).and_return([{ 'pending_wal_count' => nil }])

      expect(evaluate).to be_a(Gitlab::Database::BackgroundMigration::HealthStatus::Signals::NotAvailable)
      expect(evaluate.reason).to include('WAL archive queue can not be calculated')
    end

    it 'uses primary database' do
      expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary).and_yield

      evaluate
    end

    context 'when WAL archive queue size is below the limit' do
      it 'returns Normal signal' do
        expect(connection).to receive(:execute).and_return([{ 'pending_wal_count' => 1 }])
        expect(evaluate).to be_a(Gitlab::Database::BackgroundMigration::HealthStatus::Signals::Normal)
        expect(evaluate.reason).to include('WAL archive queue is within limit')
      end
    end

    context 'when WAL archive queue size is above the limit' do
      it 'returns Stop signal' do
        expect(connection).to receive(:execute).and_return([{ 'pending_wal_count' => 420 }])
        expect(evaluate).to be_a(Gitlab::Database::BackgroundMigration::HealthStatus::Signals::Stop)
        expect(evaluate.reason).to include('WAL archive queue is too big')
      end
    end
  end
end