1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'SRV lookup' do
context 'end to end' do
require_external_connectivity
# JRuby apparently does not implement non-blocking UDP I/O which is used
# by RubyDNS:
# NotImplementedError: recvmsg_nonblock is not implemented
fails_on_jruby
let(:uri) do
"mongodb+srv://test-fake.test.build.10gen.cc/?tls=#{SpecConfig.instance.ssl?}&tlsInsecure=true"
end
let(:client) do
new_local_client(uri,
SpecConfig.instance.ssl_options.merge(
server_selection_timeout: 3.16,
timeout: 4.11,
connect_timeout: 4.12,
resolv_options: {
nameserver: 'localhost',
nameserver_port: [['localhost', 5300], ['127.0.0.1', 5300]],
},
),
)
end
context 'DNS resolver not responding' do
it 'fails to create client' do
lambda do
client
end.should raise_error(Mongo::Error::NoSRVRecords, /The DNS query returned no SRV records for 'test-fake.test.build.10gen.cc'/)
end
it 'times out in connect_timeout' do
start_time = Mongo::Utils.monotonic_time
lambda do
client
end.should raise_error(Mongo::Error::NoSRVRecords)
elapsed_time = Mongo::Utils.monotonic_time - start_time
elapsed_time.should > 4
# The number of queries performed depends on local DNS search suffixes,
# therefore we cannot reliably assert how long it would take for this
# resolution to time out.
#elapsed_time.should < 8
end
end
end
end
|