diff options
author | Toon Claes <toon@gitlab.com> | 2018-06-26 15:27:01 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-06-27 22:43:23 +0300 |
commit | 48901bdecfe30fd201c01a608fdc3b35e4f70e08 (patch) | |
tree | 569eb85214c660dfa324415b2d1682f36aade244 /spec/lib/gitlab/shard_health_cache_spec.rb | |
parent | d98e4f88c262263a04aa9d8ce727f7bdc7202f07 (diff) |
Bring Gitlab::ShardHealthCache to CE
It already existed in EE in the Geo namespace. This change brings it
to CE.
Diffstat (limited to 'spec/lib/gitlab/shard_health_cache_spec.rb')
-rw-r--r-- | spec/lib/gitlab/shard_health_cache_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/lib/gitlab/shard_health_cache_spec.rb b/spec/lib/gitlab/shard_health_cache_spec.rb new file mode 100644 index 00000000000..e1a69261939 --- /dev/null +++ b/spec/lib/gitlab/shard_health_cache_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Gitlab::ShardHealthCache, :clean_gitlab_redis_cache do + let(:shards) { %w(foo bar) } + + before do + described_class.update(shards) + 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) + described_class.update(new_set) + + 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 + described_class.update([]) + + 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 |