Commit dcf22631 authored by Stan Hu's avatar Stan Hu

Merge branch '205640-dont-ignore-database-errors' into 'master'

Do not ignore database connection errors

See merge request gitlab-org/gitlab!29400
parents 2f1250cd b7de942a
......@@ -43,7 +43,7 @@ module Gitlab
end
def uncached_application_settings
return fake_application_settings unless connect_to_db?
return fake_application_settings if Gitlab::Runtime.rake? && !connect_to_db?
current_settings = ::ApplicationSetting.current
# If there are pending migrations, it's possible there are columns that
......
......@@ -49,20 +49,16 @@ describe Gitlab::CurrentSettings do
end
end
context 'with DB unavailable' do
context 'and settings in cache' do
include_context 'with settings in cache'
it 'fetches the settings from cache without issuing any query' do
expect(ActiveRecord::QueryRecorder.new { described_class.current_application_settings }.count).to eq(0)
end
end
context 'and no settings in cache' do
context 'in a Rake task with DB unavailable' do
before do
allow(Gitlab::Runtime).to receive(:rake?).and_return(true)
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(false)` causes issues
# during the initialization phase of the test suite, so instead let's mock the internals of it
allow(ActiveRecord::Base.connection).to receive(:active?).and_return(false)
end
context 'and no settings in cache' do
before do
expect(ApplicationSetting).not_to receive(:current)
end
......@@ -185,17 +181,6 @@ describe Gitlab::CurrentSettings do
expect(described_class.current_application_settings).to eq(:current_settings)
end
end
context 'when the application_settings table does not exist' do
it 'returns a FakeApplicationSettings object' do
expect(Gitlab::Database)
.to receive(:cached_table_exists?)
.with('application_settings')
.and_return(false)
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
end
end
end
end
end
......
......@@ -80,6 +80,9 @@ module MigrationsHelpers
allow(ActiveRecord::Base.connection)
.to receive(:active?)
.and_return(false)
allow(Gitlab::Runtime)
.to receive(:rake?)
.and_return(true)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
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