From aab3cf7b74d4941cc217ccc7d1717bad344ba93e Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Tue, 3 Apr 2012 14:15:17 -0400 Subject: [PATCH] minor: cleanup thread_to_socket pruning code and test --- lib/mongo/util/pool.rb | 11 +++-------- test/pool_test.rb | 2 -- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/mongo/util/pool.rb b/lib/mongo/util/pool.rb index a6e721a..f28ca08 100644 --- a/lib/mongo/util/pool.rb +++ b/lib/mongo/util/pool.rb @@ -227,15 +227,10 @@ module Mongo end def prune_thread_socket_hash - map = {} - Thread.list.each do |t| - map[t] = 1 - end + current_threads = Set[*Thread.list] - @threads_to_sockets.keys.each do |key| - if !map[key] - @threads_to_sockets.delete(key) - end + @threads_to_sockets.delete_if do |thread, socket| + !current_threads.include?(thread) end end diff --git a/test/pool_test.rb b/test/pool_test.rb index 0a5830d..a62f69e 100644 --- a/test/pool_test.rb +++ b/test/pool_test.rb @@ -12,12 +12,10 @@ class PoolTest < Test::Unit::TestCase @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