debian-mirror-gitlab/spec/lib/gitlab/shard_health_cache_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::ShardHealthCache, :clean_gitlab_redis_cache do
2018-11-08 19:23:39 +05:30
let(:shards) { %w(foo bar) }
before do
2022-03-02 08:16:31 +05:30
described_class.update(shards) # rubocop:disable Rails/SaveBang
2018-11-08 19:23:39 +05:30
end
describe '.clear' do
it 'leaves no shards around' do
described_class.clear
expect(described_class.healthy_shard_count).to eq(0)
end
end
describe '.update' do
it 'returns the healthy shards' do
expect(described_class.cached_healthy_shards).to match_array(shards)
end
it 'replaces the existing set' do
new_set = %w(test me more)
2022-03-02 08:16:31 +05:30
described_class.update(new_set) # rubocop:disable Rails/SaveBang
2018-11-08 19:23:39 +05:30
expect(described_class.cached_healthy_shards).to match_array(new_set)
end
end
describe '.healthy_shard_count' do
it 'returns the healthy shard count' do
expect(described_class.healthy_shard_count).to eq(2)
end
it 'returns 0 if no shards are available' do
2022-03-02 08:16:31 +05:30
described_class.update([]) # rubocop:disable Rails/SaveBang
2018-11-08 19:23:39 +05:30
expect(described_class.healthy_shard_count).to eq(0)
end
end
describe '.healthy_shard?' do
it 'returns true for a healthy shard' do
expect(described_class.healthy_shard?('foo')).to be_truthy
end
it 'returns false for an unknown shard' do
expect(described_class.healthy_shard?('unknown')).to be_falsey
end
end
end