Sha256: 4a80e47e83813efb90684161dc8259d2b6a50ebb4945e2e573672d15e8bca015

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe 'Client' do
  # TODO after the client is closed, operations should fail with an exception
  # that communicates this state, instead of failing with server selection or
  # pool errors. RUBY-3102, RUBY-3174.
  context 'after client is disconnected' do
    let(:client) { authorized_client.with(server_selection_timeout: 1) }

    before do
      client.close
    end

    it 'is still usable for operations' do
      resp = client.database.command(ping: 1)
      expect(resp).to be_a(Mongo::Operation::Result)
    end

    context 'operation that can use sessions' do
      it 'is still usable for operations' do
        client['collection'].insert_one(test: 1)
      end
    end

    context 'after all servers are marked unknown' do
      require_topology :single, :replica_set, :sharded

      before do
        client.cluster.servers.each do |server|
          server.unknown!
        end
      end

      context 'operation that never uses sessions' do
        it 'fails server selection' do
          expect do
            client.database.command(ping: 1)
          end.to raise_error(Mongo::Error::NoServerAvailable)
        end
      end

      context 'operation that can use sessions' do
        it 'fails server selection' do
          expect do
            client['collection'].insert_one(test: 1)
          end.to raise_error(Mongo::Error::NoServerAvailable)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mongo-2.21.0 spec/integration/client_spec.rb
mongo-2.20.1 spec/integration/client_spec.rb
mogno-2.20.0 spec/integration/client_spec.rb
mogno-1.0.0 spec/integration/client_spec.rb
mongo-2.20.0 spec/integration/client_spec.rb
mongo-2.19.3 spec/integration/client_spec.rb
mongo-2.19.2 spec/integration/client_spec.rb
mongo-2.19.1 spec/integration/client_spec.rb
mongo-2.19.0 spec/integration/client_spec.rb