Commit b3161695 authored by Thong Kuah's avatar Thong Kuah

LB feature is available in FOSS but is not ready

As we have some code in ee/ uses LB, in overriden methods
and may have the (incorrect) assumption that LB is not present in FOSS
parent 0f4e4830
......@@ -102,23 +102,9 @@ module Gitlab
hosts.any? || service_discovery_enabled?
end
# Temporarily disabled for FOSS until move from EE to FOSS is complete
def self.feature_available?
# If this method is called in any subscribers listening to
# sql.active_record, the SQL call below may cause infinite recursion.
# So, the memoization variable must have 3 states
# - First call: @feature_available is undefined
# -> Set @feature_available to false
# -> Trigger SQL
# -> SQL subscriber triggers this method again
# -> return false
# -> Set @feature_available to true
# -> return true
# - Second call: return @feature_available right away
return @feature_available if defined?(@feature_available)
@feature_available = false
@feature_available = Gitlab::Database.cached_table_exists?('licenses') &&
::License.feature_available?(:db_load_balancing)
Gitlab.ee? || Gitlab::Utils.to_boolean(ENV['ENABLE_LOAD_BALANCING_FOR_FOSS'], default: false)
end
def self.start_service_discovery
......
......@@ -5,6 +5,10 @@ require 'spec_helper'
RSpec.describe Gitlab::Database::LoadBalancing do
include_context 'clear DB Load Balancing configuration'
before do
stub_env('ENABLE_LOAD_BALANCING_FOR_FOSS', 'true')
end
describe '.proxy' do
context 'when configured' do
before do
......@@ -127,8 +131,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
describe '.enable?' do
let!(:license) { create(:license, plan: ::License::PREMIUM_PLAN) }
before do
clear_load_balancing_configuration
allow(described_class).to receive(:hosts).and_return(%w(foo))
......@@ -181,27 +183,22 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
end
context 'without a license' do
context 'FOSS' do
before do
License.destroy_all # rubocop: disable Cop/DestroyAll
clear_load_balancing_configuration
end
allow(Gitlab).to receive(:ee?).and_return(false)
it 'is disabled' do
expect(described_class.enable?).to eq(false)
stub_env('ENABLE_LOAD_BALANCING_FOR_FOSS', 'false')
end
end
context 'with an EES license' do
let!(:license) { create(:license, plan: ::License::STARTER_PLAN) }
it 'is disabled' do
expect(described_class.enable?).to eq(false)
end
end
context 'with an EEP license' do
let!(:license) { create(:license, plan: ::License::PREMIUM_PLAN) }
context 'EE' do
before do
allow(Gitlab).to receive(:ee?).and_return(true)
end
it 'is enabled' do
allow(described_class).to receive(:hosts).and_return(%w(foo))
......@@ -213,8 +210,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
describe '.configured?' do
let!(:license) { create(:license, plan: ::License::PREMIUM_PLAN) }
before do
clear_load_balancing_configuration
end
......@@ -245,17 +240,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
expect(described_class.configured?).to eq(false)
end
context 'without a license' do
before do
License.destroy_all # rubocop: disable Cop/DestroyAll
clear_load_balancing_configuration
end
it 'is not configured' do
expect(described_class.configured?).to eq(false)
end
end
end
describe '.configure_proxy' do
......@@ -444,7 +428,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
before do
stub_licensed_features(db_load_balancing: true)
# Preloading testing class
model.singleton_class.prepend ::Gitlab::Database::LoadBalancing::ActiveRecordProxy
......
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