Commit f589b365 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '350651-fix-remaining-code-offenses-using-activerecord-base-methods-3' into 'master'

Fix use of ActiveRecord::Base in DbCheck

See merge request gitlab-org/gitlab!80433
parents ce903c1a eab9b847
......@@ -13,12 +13,14 @@ module Gitlab
end
def successful?(result)
result == '1'
result == Gitlab::Database.database_base_models.size
end
def check
catch_timeout 10.seconds do
ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.[]('ping')&.to_s
Gitlab::Database.database_base_models.sum do |_, base|
base.connection.select_value('SELECT 1')
end
end
end
end
......
......@@ -4,5 +4,20 @@ require 'spec_helper'
require_relative './simple_check_shared'
RSpec.describe Gitlab::HealthChecks::DbCheck do
include_examples 'simple_check', 'db_ping', 'Db', '1'
include_examples 'simple_check', 'db_ping', 'Db', Gitlab::Database.database_base_models.size
context 'with multiple databases' do
subject { described_class.readiness }
before do
allow(Gitlab::Database).to receive(:database_base_models)
.and_return({ main: ApplicationRecord, ci: Ci::ApplicationRecord }.with_indifferent_access)
end
it 'checks multiple databases' do
expect(ApplicationRecord.connection).to receive(:select_value).with('SELECT 1').and_call_original
expect(Ci::ApplicationRecord.connection).to receive(:select_value).with('SELECT 1').and_call_original
expect(subject).to have_attributes(success: true)
end
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