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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
require 'spec_helper'
describe Mongo::Server::Monitor::Connection do
let(:client) do
authorized_client.with(options)
end
let(:address) do
client.cluster.next_primary.address
end
let(:cluster) do
double('cluster').tap do |cl|
allow(cl).to receive(:topology).and_return(double('topology'))
allow(cl).to receive(:app_metadata).and_return(Mongo::Cluster::AppMetadata.new(authorized_client.cluster))
end
end
let(:server) do
Mongo::Server.new(address,
cluster,
Mongo::Monitoring.new(monitoring: false),
Mongo::Event::Listeners.new, options)
end
let(:connection) do
server.monitor.connection
end
after do
client.close
end
context 'when a connect_timeout is in the options' do
context 'when a socket_timeout is in the options' do
let(:options) do
TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: 5)
end
before do
connection.connect!
end
it 'uses the connect_timeout for the address' do
expect(connection.address.send(:connect_timeout)).to eq(3)
end
it 'uses the connect_timeout as the socket_timeout' do
expect(connection.send(:socket).timeout).to eq(3)
end
end
context 'when a socket_timeout is not in the options' do
let(:options) do
TEST_OPTIONS.merge(connect_timeout: 3, socket_timeout: nil)
end
before do
connection.connect!
end
it 'uses the connect_timeout for the address' do
expect(connection.address.send(:connect_timeout)).to eq(3)
end
it 'uses the connect_timeout as the socket_timeout' do
expect(connection.send(:socket).timeout).to eq(3)
end
end
end
context 'when a connect_timeout is not in the options' do
context 'when a socket_timeout is in the options' do
let(:options) do
TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: 5)
end
before do
connection.connect!
end
it 'uses the default connect_timeout for the address' do
expect(connection.address.send(:connect_timeout)).to eq(10)
end
it 'uses the connect_timeout as the socket_timeout' do
expect(connection.send(:socket).timeout).to eq(10)
end
end
context 'when a socket_timeout is not in the options' do
let(:options) do
TEST_OPTIONS.merge(connect_timeout: nil, socket_timeout: nil)
end
before do
connection.connect!
end
it 'uses the default connect_timeout for the address' do
expect(connection.address.send(:connect_timeout)).to eq(10)
end
it 'uses the connect_timeout as the socket_timeout' do
expect(connection.send(:socket).timeout).to eq(10)
end
end
end
end
|