@@ -519,7 +519,7 @@ def test_operation_timeout_with_active
519519 context "Socket pools" do
520520 context "checking out writers" do
521521 setup do
522- @con = standard_connection ( :pool_size => 10 , :pool_timeout => 10 )
522+ @con = standard_connection ( :pool_size => 10 , :pool_timeout => 2 )
523523 @coll = @con [ TEST_DB ] [ 'test-connection-exceptions' ]
524524 end
525525
@@ -533,13 +533,42 @@ def test_operation_timeout_with_active
533533 end
534534 end
535535
536- should "close the connection on send_message_with_gle for major exceptions" do
537- @con . stubs ( :checkout_writer ) . raises ( SystemStackError )
538- @con . stubs ( :checkout_reader ) . raises ( SystemStackError )
539- @con . expects ( :close )
540- begin
541- @coll . insert ( { :foo => "bar" } , :w => 1 )
542- rescue SystemStackError
536+ context "with GLE" do
537+ setup do
538+ # Force this connection to use send_message_with_gle for these tests
539+ @con . stubs ( :use_write_command? ) . returns ( false )
540+ end
541+
542+ should "close the connection on send_message_with_gle for major exceptions" do
543+ @con . stubs ( :checkout_writer ) . raises ( SystemStackError )
544+ @con . stubs ( :checkout_reader ) . raises ( SystemStackError )
545+ @con . expects ( :close )
546+ begin
547+ @coll . insert ( { :foo => "bar" } , :w => 1 )
548+ rescue SystemStackError
549+ end
550+ end
551+
552+ should "release the connection on send_message_with_gle for connection exceptions" do
553+ mock_writer = mock ( :close => true )
554+ mock_writer . expects ( :read ) . raises ( ConnectionFailure )
555+ @con . expects ( :send_message_on_socket )
556+
557+ @con . stubs ( :checkout_writer ) . returns ( mock_writer )
558+ @con . expects ( :checkin ) . with ( mock_writer )
559+ @coll . insert ( { :foo => "bar" } , :w => 1 ) rescue nil
560+ end
561+
562+ should "release the connection on send_message_with_gle for all exceptions" do
563+ mock_writer = mock ( )
564+ mock_writer . expects ( :read ) . raises ( ArgumentError )
565+ @con . expects ( :send_message_on_socket )
566+ @con . stubs ( :checkout_writer ) . returns ( mock_writer )
567+ @con . expects ( :checkin ) . with ( mock_writer ) . once
568+ begin
569+ @coll . insert ( { :foo => "bar" } , :w => 1 )
570+ rescue ArgumentError
571+ end
543572 end
544573 end
545574
0 commit comments