Sha256: 6d78687401c8b3ab4b164dee74d9d22585d3460ea63fc28a3e966dbb731c3381

Contents?: true

Size: 1.21 KB

Versions: 52

Compression:

Stored size: 1.21 KB

Contents

require './test/test_helper'
require 'thread'

class PoolTest < Test::Unit::TestCase
  include Mongo

  def setup
    @connection = standard_connection
  end

  def test_pool_affinity
    @pool = Pool.new(@connection, TEST_HOST, TEST_PORT, :size => 5)

    @threads    = []
    @sockets    = []

    10.times do
      @threads << Thread.new do
        original_socket = @pool.checkout
        @sockets << original_socket
        @pool.checkin(original_socket)
        5000.times do
          socket = @pool.checkout
          assert_equal original_socket, socket
          @pool.checkin(socket)
        end
      end
    end

    @threads.each { |t| t.join }
  end

  def test_pool_thread_pruning
    @pool = Pool.new(@connection, TEST_HOST, TEST_PORT, :size => 5)

    @threads = []

    10.times do
      @threads << Thread.new do
        50.times do
          socket = @pool.checkout
          @pool.checkin(socket)
        end
      end
    end

    @threads.each { |t| t.join }
    assert_equal 10, @pool.instance_variable_get(:@threads_to_sockets).size

    # Thread-socket pool
    10000.times do
      @pool.checkin(@pool.checkout)
    end

    assert_equal 1, @pool.instance_variable_get(:@threads_to_sockets).size
  end
end

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
classiccms-0.5.13 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.12 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.11 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.10 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.9 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.8 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.7 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.6 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.5 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.2 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.1 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.5.0 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.4.2 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.4.1 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.4.0 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.3.9 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.3.8 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.3.7 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.3.6 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb
classiccms-0.3.5 vendor/bundle/gems/mongo-1.6.1/test/pool_test.rb