Commit c022c44a authored by Brett Walker's avatar Brett Walker

raise SecondaryNotConfigured if Geo DB is not found

parent 3549ee7a
...@@ -4,6 +4,7 @@ module Geo ...@@ -4,6 +4,7 @@ module Geo
class TrackingBase < ActiveRecord::Base class TrackingBase < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
NOT_CONFIGURED_MSG = 'Geo secondary database is not configured'.freeze
SecondaryNotConfigured = Class.new(StandardError) SecondaryNotConfigured = Class.new(StandardError)
if ::Gitlab::Geo.geo_database_configured? if ::Gitlab::Geo.geo_database_configured?
...@@ -12,13 +13,15 @@ module Geo ...@@ -12,13 +13,15 @@ module Geo
def self.connection def self.connection
unless ::Gitlab::Geo.geo_database_configured? unless ::Gitlab::Geo.geo_database_configured?
message = 'Geo secondary database is not configured' message = NOT_CONFIGURED_MSG
message += "\nIn the GDK root, try running `make geo-setup`" if Rails.env.development? message += "\nIn the GDK root, try running `make geo-setup`" if Rails.env.development?
raise SecondaryNotConfigured.new(message) raise SecondaryNotConfigured.new(message)
end end
# Don't call super because LoadBalancing::ActiveRecordProxy will intercept it # Don't call super because LoadBalancing::ActiveRecordProxy will intercept it
retrieve_connection retrieve_connection
rescue ActiveRecord::NoDatabaseError
raise SecondaryNotConfigured.new(NOT_CONFIGURED_MSG)
end end
end end
end end
---
title: no longer fail when setting up Geo database with GDK
merge_request: 6680
author:
type: fixed
require 'spec_helper'
describe Geo::TrackingBase do
it 'raises when Geo database is not configured' do
allow(Gitlab::Geo).to receive(:geo_database_configured?).and_return(false)
expect(described_class).not_to receive(:retrieve_connection)
expect { described_class.connection }.to raise_error(Geo::TrackingBase::SecondaryNotConfigured)
end
it 'raises when Geo database is not found' do
allow(Gitlab::Geo).to receive(:geo_database_configured?).and_return(true)
allow(described_class).to receive(:retrieve_connection).and_raise(ActiveRecord::NoDatabaseError.new('not found'))
expect(described_class).to receive(:retrieve_connection)
expect { described_class.connection }.to raise_error(Geo::TrackingBase::SecondaryNotConfigured)
end
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