Commit 4b12a6ab authored by Stan Hu's avatar Stan Hu

More clean up with GeoNodeStatus

parent f90d7af4
......@@ -159,7 +159,7 @@ class GeoNodeStatus < ActiveRecord::Base
def storage_shards_match?
return unless Gitlab::Geo.primary?
shards_match?(storage_shards.as_json, current_shards.as_json)
shards_match?(current_shards, primary_shards)
end
def [](key)
......@@ -169,7 +169,15 @@ class GeoNodeStatus < ActiveRecord::Base
private
def current_shards
StorageShardSerializer.new.represent(StorageShard.all)
serialize_storage_shards(storage_shards)
end
def primary_shards
serialize_storage_shards(StorageShard.all)
end
def serialize_storage_shards(shards)
StorageShardSerializer.new.represent(shards).as_json
end
def shards_match?(first, second)
......
......@@ -425,22 +425,22 @@ describe GeoNodeStatus, :geo do
it 'returns false if the storage shards do not match' do
status = create(:geo_node_status)
status.storage_shards.first['name'] = 'broken-shard'
data = status.as_json
data = GeoNodeStatusSerializer.new.represent(status).as_json
data['storage_shards'].first['name'] = 'broken-shard'
result = GeoNodeStatus.from_json(data)
expect(status.storage_shards_match?).to be false
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 = status.as_json
data = GeoNodeStatusSerializer.new.represent(status).as_json
result = GeoNodeStatus.from_json(data)
expect(status.storage_shards_match?).to be true
expect(result.storage_shards_match?).to be true
end
end
end
......@@ -2,7 +2,7 @@ FactoryBot.define do
factory :geo_node_status do
sequence(:id)
geo_node
storage_shards { StorageShardSerializer.new.represent(StorageShard.all) }
storage_shards { StorageShard.all }
trait :healthy do
health nil
......
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