Sha256: fd2fa34da2b721d801cf915096eca56e1f79d8959247cd08e14c4adaf7f24740

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

require_relative '../../../lib/locomotive/steam/adapters/mongodb.rb'

describe Locomotive::Steam::MongoDBAdapter do

  let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: mongodb_database, hosts: ['127.0.0.1:27017'], min_pool_size: 2, max_pool_size: 5) }

  before(:all) do
    described_class.disconnect_session
    @before_connections = current_connections
  end

  describe '#session' do

    subject { adapter.send(:session) }

    it { is_expected.not_to eq nil }

    it "don't create more Mongo sessions than the max pool" do
      10.times { subject['locomotive_sites'].find.count }
      _after = current_connections
      expect(_after).to be >= (@before_connections + 2) # min_pool_size
      expect(_after).to be <= (@before_connections + 5) # max_pool_size
    end

  end

  describe '.disconnect_session' do

    let(:connection) { adapter.send(:session) }

    subject { described_class.disconnect_session }

    it 'closes clients' do
      10.times { connection['locomotive_sites'].find.count }      
      @before_connections = current_connections
      is_expected.to eq true
      sleep(2) # NOTE: wait for the connections to be completely closed
      expect(current_connections).to be < @before_connections
    end

  end

  def current_connections
    `mongo --eval "db.serverStatus().connections.current"`.split("\n").last.to_i
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
locomotivecms_steam-1.6.1 spec/integration/adapters/mongodb_spec.rb
locomotivecms_steam-1.6.0 spec/integration/adapters/mongodb_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/integration/adapters/mongodb_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/integration/adapters/mongodb_spec.rb