debian-mirror-gitlab/spec/models/postgresql/replication_slot_spec.rb

60 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
require 'spec_helper'
2019-10-12 21:52:04 +05:30
describe Postgresql::ReplicationSlot do
2018-12-13 13:39:08 +05:30
describe '.in_use?' do
it 'returns true when replication slots are present' do
expect(described_class).to receive(:exists?).and_return(true)
expect(described_class.in_use?).to be_truthy
end
it 'returns false when replication slots are not present' do
expect(described_class.in_use?).to be_falsey
end
it 'returns false if the existence check is invalid' do
expect(described_class).to receive(:exists?).and_raise(ActiveRecord::StatementInvalid.new('PG::FeatureNotSupported'))
expect(described_class.in_use?).to be_falsey
end
end
2018-11-18 11:00:15 +05:30
describe '.lag_too_great?' do
2018-12-13 13:39:08 +05:30
before do
expect(described_class).to receive(:in_use?).and_return(true)
end
2018-11-18 11:00:15 +05:30
it 'returns true when replication lag is too great' do
expect(described_class)
.to receive(:pluck)
.and_return([125.megabytes])
expect(described_class.lag_too_great?).to eq(true)
end
it 'returns false when more than one replicas is up to date enough' do
expect(described_class)
.to receive(:pluck)
.and_return([125.megabytes, 0.megabytes, 0.megabytes])
expect(described_class.lag_too_great?).to eq(false)
end
it 'returns false when replication lag is not too great' do
expect(described_class)
.to receive(:pluck)
.and_return([0.megabytes])
expect(described_class.lag_too_great?).to eq(false)
end
2019-09-30 21:07:59 +05:30
it 'returns false when there is a nil replication lag' do
expect(described_class)
.to receive(:pluck)
.and_return([0.megabytes, nil])
expect(described_class.lag_too_great?).to eq(false)
end
2018-11-18 11:00:15 +05:30
end
end