Commit 67522028 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'id-avoid-stubbing-geo-node' into 'master'

Avoid stubbing a Geo node instance

See merge request gitlab-org/gitlab!60674
parents ec3294c9 c7870ec9
......@@ -40,7 +40,7 @@ module Resolvers
# We can't query other nodes' tracking databases
def geo_node_is_current?
geo_node&.current?
GeoNode.current?(geo_node)
end
def geo_node
......
......@@ -102,6 +102,10 @@ class GeoNode < ApplicationRecord
left_join_status.minimum(:cursor_last_event_id)
end
def current?(node)
node.present? && current_node_name == node.name
end
# Tries to find a GeoNode by oauth_application_id, returning nil if none could be found.
def find_by_oauth_application_id(oauth_application_id)
find_by(oauth_application_id: oauth_application_id)
......@@ -117,10 +121,6 @@ class GeoNode < ApplicationRecord
end
end
def current?
self.class.current_node_name == name
end
def secondary?
!primary
end
......
......@@ -133,7 +133,7 @@ module API
def geo_node_status
strong_memoize(:geo_node_status) do
status = GeoNodeStatus.fast_current_node_status if geo_node.current?
status = GeoNodeStatus.fast_current_node_status if GeoNode.current?(geo_node)
status || geo_node.status
end
end
......
......@@ -12,7 +12,6 @@ module EE
expose :internal_url
expose :primary?, as: :primary
expose :enabled
expose :current?, as: :current
expose :files_max_capacity
expose :repos_max_capacity
expose :verification_max_capacity
......@@ -49,6 +48,10 @@ module EE
expose_url api_v4_geo_nodes_repair_path(id: geo_node.id)
end
end
expose :current do |geo_node|
::GeoNode.current?(geo_node)
end
end
end
end
......
......@@ -361,17 +361,17 @@ RSpec.describe GeoNode, :request_store, :geo, type: :model do
end
end
describe '#current?' do
describe '.current?' do
it 'returns true when node is the current node' do
node = described_class.new(name: described_class.current_node_name)
expect(node.current?).to be_truthy
expect(described_class.current?(node)).to be_truthy
end
it 'returns false when node is not the current node' do
node = described_class.new(name: 'some other node')
expect(node.current?).to be_falsy
expect(described_class.current?(node)).to be_falsy
end
end
......
......@@ -4,7 +4,11 @@ module EE
module GeoHelpers
def stub_current_geo_node(node)
allow(::Gitlab::Geo).to receive(:current_node).and_return(node)
allow(node).to receive(:current?).and_return(true) unless node.nil?
# GeoNode.current? returns true only when the node is passed
# otherwise it returns false
allow(GeoNode).to receive(:current?).and_return(false)
allow(GeoNode).to receive(:current?).with(node).and_return(true)
end
def stub_current_node_name(name)
......@@ -21,14 +25,6 @@ module EE
allow(::Gitlab::Geo).to receive(:secondary?).and_return(true)
end
def stub_node_disabled(node)
allow(node).to receive(:enabled?).and_return(false)
end
def stub_selective_sync(node, value)
allow(node).to receive(:selective_sync?).and_return(value)
end
def create_project_on_shard(shard_name)
project = create(:project)
......
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