Commit 4180b3de authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-handle-no-shard-data-available' into 'master'

Gracefully handle case when no shard data is available

See merge request gitlab-org/gitlab-ee!4051
parents 6ffacd08 eb7df045
......@@ -175,6 +175,7 @@ class GeoNodeStatus < ActiveRecord::Base
# from a remote node via JSON.
def storage_shards_match?
return unless Gitlab::Geo.primary?
return unless current_shards && primary_shards
shards_match?(current_shards, primary_shards)
end
......
......@@ -476,22 +476,24 @@ describe GeoNodeStatus, :geo do
describe '#storage_shards_match?' do
before { stub_primary_node }
set(:status) { create(:geo_node_status) }
let(:data) { GeoNodeStatusSerializer.new.represent(status).as_json }
let(:result) { described_class.from_json(data) }
it 'returns nil if no shard data is available' do
data.delete('storage_shards')
expect(result.storage_shards_match?).to be nil
end
it 'returns false if the storage shards do not match' do
status = create(:geo_node_status)
data = GeoNodeStatusSerializer.new.represent(status).as_json
data['storage_shards'].first['name'] = 'broken-shard'
result = described_class.from_json(data)
expect(result.storage_shards_match?).to be false
end
it 'returns true if the storage shards match in different order' do
status = create(:geo_node_status)
status.storage_shards.shuffle!
data = GeoNodeStatusSerializer.new.represent(status).as_json
result = described_class.from_json(data)
expect(result.storage_shards_match?).to be true
end
......
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