Commit f06e8de8 authored by Thong Kuah's avatar Thong Kuah

Enchance spec coverage

Impove DB load balancing spec coverage with regards to logger
parent d8c8ee46
...@@ -77,29 +77,50 @@ describe Gitlab::Database::LoadBalancing::Host do ...@@ -77,29 +77,50 @@ describe Gitlab::Database::LoadBalancing::Host do
it 'marks the host as offline' do it 'marks the host as offline' do
expect(host.pool).to receive(:disconnect!) expect(host.pool).to receive(:disconnect!)
expect(Gitlab::Database::LoadBalancing::Logger).to receive(:warn)
.with(hash_including(event: :host_offline))
.and_call_original
host.offline! host.offline!
end end
end end
describe '#online?' do describe '#online?' do
context 'when the replica status is recent enough' do context 'when the replica status is recent enough' do
before do
expect(host).to receive(:check_replica_status?).and_return(false)
end
it 'returns the latest status' do it 'returns the latest status' do
Timecop.freeze do expect(host).not_to receive(:refresh_status)
host = described_class.new('localhost', load_balancer) expect(Gitlab::Database::LoadBalancing::Logger).not_to receive(:info)
expect(Gitlab::Database::LoadBalancing::Logger).not_to receive(:warn)
expect(host).not_to receive(:refresh_status) expect(host).to be_online
expect(host).to be_online
end
end end
end
context 'when the replica status is outdated' do it 'returns an offline status' do
it 'refreshes the status' do
host.offline! host.offline!
expect(host).not_to receive(:refresh_status)
expect(Gitlab::Database::LoadBalancing::Logger).not_to receive(:info)
expect(Gitlab::Database::LoadBalancing::Logger).not_to receive(:warn)
expect(host).not_to be_online
end
end
context 'when the replica status is outdated' do
before do
expect(host) expect(host)
.to receive(:check_replica_status?) .to receive(:check_replica_status?)
.and_return(true) .and_return(true)
end
it 'refreshes the status' do
expect(Gitlab::Database::LoadBalancing::Logger).to receive(:info)
.with(hash_including(event: :host_online))
.and_call_original
expect(host).to be_online expect(host).to be_online
end end
...@@ -270,9 +291,7 @@ describe Gitlab::Database::LoadBalancing::Host do ...@@ -270,9 +291,7 @@ describe Gitlab::Database::LoadBalancing::Host do
describe '#replication_lag_size' do describe '#replication_lag_size' do
it 'returns the lag size as an Integer' do it 'returns the lag size as an Integer' do
# On newer versions of Ruby the class is Integer, but on CI we run a expect(host.replication_lag_size).to be_an_instance_of(Integer)
# version that still uses Fixnum.
expect([Fixnum, Integer]).to include(host.replication_lag_size.class) # rubocop: disable Lint/UnifiedInteger
end end
it 'returns nil when the database query returned no rows' do it 'returns nil when the database query returned no rows' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment