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
|
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'Server' do
let(:client) { authorized_client }
let(:context) { Mongo::Operation::Context.new(client: client) }
let(:server) { client.cluster.next_primary }
let(:collection) { client['collection'] }
let(:view) { Mongo::Collection::View.new(collection) }
describe 'operations when client/cluster are disconnected' do
context 'it performs read operations and receives the correct result type' do
context 'normal server' do
it 'can be used for reads' do
result = view.send(:send_initial_query, server, context)
expect(result).to be_a(Mongo::Operation::Find::Result)
end
end
context 'known server in disconnected cluster' do
require_topology :single, :replica_set, :sharded
require_no_linting
before do
server.disconnect!
expect(server).not_to be_unknown
end
after do
server.close
end
it 'can be used for reads' do
# See also RUBY-3102.
result = view.send(:send_initial_query, server, context)
expect(result).to be_a(Mongo::Operation::Find::Result)
end
end
context 'unknown server in disconnected cluster' do
require_topology :single, :replica_set, :sharded
require_no_linting
before do
client.close
server.unknown!
expect(server).to be_unknown
end
after do
server.close
end
it 'is unusable' do
# See also RUBY-3102.
lambda do
view.send(:send_initial_query, server, context)
end.should raise_error(Mongo::Error::ServerNotUsable)
end
end
end
end
end
|