Commit e460765d authored by Thong Kuah's avatar Thong Kuah

Do not run service discovery for DB load balancing for rake tasks

Changelog: fixed
parent a9a8dd14
...@@ -107,7 +107,11 @@ module Gitlab ...@@ -107,7 +107,11 @@ module Gitlab
hosts.any? || service_discovery_enabled? hosts.any? || service_discovery_enabled?
end end
# This is disabled for Rake tasks to ensure e.g. database migrations
# always produce consistent results.
def service_discovery_enabled? def service_discovery_enabled?
return false if Gitlab::Runtime.rake?
service_discovery[:record].present? service_discovery[:record].present?
end end
......
...@@ -140,6 +140,15 @@ RSpec.describe Gitlab::Database::LoadBalancing::Configuration do ...@@ -140,6 +140,15 @@ RSpec.describe Gitlab::Database::LoadBalancing::Configuration do
end end
describe '#service_discovery_enabled?' do describe '#service_discovery_enabled?' do
it 'returns false when running inside a Rake task' do
allow(Gitlab::Runtime).to receive(:rake?).and_return(true)
config = described_class.new(ActiveRecord::Base)
config.service_discovery[:record] = 'foo'
expect(config.service_discovery_enabled?).to eq(false)
end
it 'returns true when a record is configured' do it 'returns true when a record is configured' do
config = described_class.new(ActiveRecord::Base) config = described_class.new(ActiveRecord::Base)
config.service_discovery[:record] = 'foo' config.service_discovery[:record] = 'foo'
......
...@@ -4,9 +4,10 @@ require 'spec_helper' ...@@ -4,9 +4,10 @@ require 'spec_helper'
RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do
let(:load_balancer) do let(:load_balancer) do
Gitlab::Database::LoadBalancing::LoadBalancer.new( configuration = Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base)
Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base) configuration.service_discovery[:record] = 'localhost'
)
Gitlab::Database::LoadBalancing::LoadBalancer.new(configuration)
end end
let(:service) do let(:service) do
...@@ -86,6 +87,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do ...@@ -86,6 +87,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do
service.perform_service_discovery service.perform_service_discovery
end end
end end
context 'with failures' do context 'with failures' do
before do before do
allow(Gitlab::ErrorTracking).to receive(:track_exception) allow(Gitlab::ErrorTracking).to receive(:track_exception)
......
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