From fa0a9337800c44872e28b928541efbbafd988ca2 Mon Sep 17 00:00:00 2001 From: Mauro Pompilio Date: Wed, 23 Feb 2011 15:29:44 +0000 Subject: [PATCH] Fix the exception message shown when there's an IOError while closing a socket in the pool. --- lib/mongo/util/pool.rb | 3 +-- test/connection_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/mongo/util/pool.rb b/lib/mongo/util/pool.rb index 61cf394..eb8c19a 100644 --- a/lib/mongo/util/pool.rb +++ b/lib/mongo/util/pool.rb @@ -49,8 +49,7 @@ module Mongo begin sock.close rescue IOError => ex - warn "IOError when attempting to close socket connected " - + "to #{@host}:#{@port}: #{ex.inspect}" + warn "IOError when attempting to close socket connected to #{@host}:#{@port}: #{ex.inspect}" end end @host = @port = nil diff --git a/test/connection_test.rb b/test/connection_test.rb index d66332b..9aefbb9 100644 --- a/test/connection_test.rb +++ b/test/connection_test.rb @@ -264,5 +264,15 @@ class TestConnection < Test::Unit::TestCase end assert_equal 0, @con.primary_pool.checked_out.size end + + should "show a proper exception message if an IOError is raised while closing a socket" do + fake_socket = Mocha::Mock.new + fake_socket.stubs(:close).raises(IOError.new) + fake_socket.stub_everything + TCPSocket.expects(:new).returns(fake_socket) + + @con.primary_pool.checkout_new_socket + assert_equal [], @con.primary_pool.close + end end end