diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) | |
download | gitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb b/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb index 984d60e9962..bfd9c644ffa 100644 --- a/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb +++ b/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do +RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery, feature_category: :database do let(:load_balancer) do configuration = Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base) configuration.service_discovery[:record] = 'localhost' @@ -23,6 +23,8 @@ RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do resource = double(:resource, address: IPAddr.new('127.0.0.1')) packet = double(:packet, answer: [resource]) + service.instance_variable_set(:@nameserver_ttl, Gitlab::Database::LoadBalancing::Resolver::FAR_FUTURE_TTL) + allow(Net::DNS::Resolver).to receive(:start) .with('localhost', Net::DNS::A) .and_return(packet) @@ -362,4 +364,52 @@ RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do expect(service.addresses_from_load_balancer).to eq(addresses) end end + + describe '#resolver', :freeze_time do + context 'without predefined resolver' do + it 'fetches a new resolver and assigns it to the instance variable' do + expect(service.instance_variable_get(:@resolver)).not_to be_present + + service_resolver = service.resolver + + expect(service.instance_variable_get(:@resolver)).to be_present + expect(service_resolver).to be_present + end + end + + context 'with predefined resolver' do + let(:resolver) do + Net::DNS::Resolver.new( + nameservers: 'localhost', + port: 8600 + ) + end + + before do + service.instance_variable_set(:@resolver, resolver) + end + + context "when nameserver's TTL is in the future" do + it 'returns the existing resolver' do + expect(service.resolver).to eq(resolver) + end + end + + context "when nameserver's TTL is in the past" do + before do + service.instance_variable_set( + :@nameserver_ttl, + 1.minute.ago + ) + end + + it 'fetches new resolver' do + service_resolver = service.resolver + + expect(service_resolver).to be_present + expect(service_resolver).not_to eq(resolver) + end + end + end + end end |