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