Sha256: 4a4a0e1e140397407ca9ef4d6589a42e62bbad3ca60ac08d5ef4d3dd42b46336

Contents?: true

Size: 1.92 KB

Versions: 16

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe 'Server' do
  let(:client) { authorized_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
    shared_examples '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)
          expect(result).to be_a(result_class)
        end
      end

      context 'known server in disconnected cluster' do
        before do
          client.close
          expect(server).not_to be_unknown
        end

        it 'can be used for reads' do
          result = view.send(:send_initial_query, server)
          expect(result).to be_a(result_class)
        end
      end

      context 'unknown server in disconnected cluster' do
        require_topology :single, :replica_set, :sharded

        before do
          client.close
          server.unknown!
          expect(server).to be_unknown
        end

        it 'can be used for reads' do
          result = view.send(:send_initial_query, server)
          expect(result).to be_a(result_class)
        end
      end
    end

    context 'for servers with FCV >= 3.4' do
      min_server_fcv '3.2'

      let(:result_class) { Mongo::Operation::Find::Result }

      it_behaves_like 'it performs read operations and receives the correct result type'
    end

    context 'for servers with FCV < 3.4' do
      # Find command was introduced in server version 3.2, so older versions should
      # receive legacy result types.
      max_server_fcv '3.0'

      let(:result_class) { Mongo::Operation::Find::Legacy::Result }

      it_behaves_like 'it performs read operations and receives the correct result type'
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/server_spec.rb
mongo-2.17.4 spec/integration/server_spec.rb
mongo-2.18.3 spec/integration/server_spec.rb
mongo-2.18.2 spec/integration/server_spec.rb
mongo-2.17.3 spec/integration/server_spec.rb
mongo-2.18.1 spec/integration/server_spec.rb
mongo-2.18.0 spec/integration/server_spec.rb
mongo-2.17.2 spec/integration/server_spec.rb
mongo-2.16.3 spec/integration/server_spec.rb
mongo-2.18.0.beta1 spec/integration/server_spec.rb
mongo-2.16.2 spec/integration/server_spec.rb
mongo-2.17.1 spec/integration/server_spec.rb
mongo-2.16.1 spec/integration/server_spec.rb
mongo-2.17.0 spec/integration/server_spec.rb
mongo-2.16.0 spec/integration/server_spec.rb
mongo-2.16.0.alpha1 spec/integration/server_spec.rb