Commit 97a3733f authored by Stan Hu's avatar Stan Hu

Merge branch 'dblb-split-ns-resolution' into 'master'

Catch NoResponseError from Net::DNS in LoadBalancing::Resolver

See merge request gitlab-org/gitlab!57187
parents 4d75765a 3e33c161
---
title: Catch NoResponseError from Net::DNS in LoadBalancing::Resolver
merge_request: 57187
author:
type: fixed
......@@ -43,6 +43,8 @@ module Gitlab
return if answer.empty?
answer.first.address
rescue Net::DNS::Resolver::NoResponseError
raise UnresolvableNameserverError, "no response from DNS server(s)"
end
end
end
......
......@@ -57,6 +57,23 @@ RSpec.describe Gitlab::Database::LoadBalancing::Resolver do
)
end
end
context 'when DNS does not respond' do
it 'raises an exception' do
allow_next_instance_of(Resolv::Hosts) do |instance|
allow(instance).to receive(:getaddress).with('localhost').and_raise(Resolv::ResolvError)
end
allow(Net::DNS::Resolver).to receive(:start)
.with('localhost', Net::DNS::A)
.and_raise(Net::DNS::Resolver::NoResponseError)
expect { subject }.to raise_exception(
described_class::UnresolvableNameserverError,
'no response from DNS server(s)'
)
end
end
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