rb: Thrift::Socket should return false from #open? if an error occurred during a...
authorKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:16:11 +0000 (01:16 +0000)
committerKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:16:11 +0000 (01:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669000 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/transport/socket.rb
lib/rb/spec/socket_spec.rb

index 77abdc3..6b648cf 100644 (file)
@@ -35,6 +35,8 @@ module Thrift
       begin
         @handle.write(str)
       rescue StandardError
+        @handle.close
+        @handle = nil
         raise TransportException.new(TransportException::NOT_OPEN)
       end
     end
@@ -47,6 +49,8 @@ module Thrift
           data = @handle.read(sz)
         end
       rescue StandardError => e
+        @handle.close
+        @handle = nil
         raise TransportException.new(TransportException::NOT_OPEN, e.message)
       end
       if (data.nil? or data.length == 0)
index 4d129b0..4f5868b 100644 (file)
@@ -6,6 +6,7 @@ class ThriftSocketSpec < Spec::ExampleGroup
   before(:each) do
     @socket = Socket.new
     @handle = mock("Handle")
+    @handle.stub!(:close)
   end
 
   describe Socket do
@@ -68,14 +69,12 @@ class ThriftSocketSpec < Spec::ExampleGroup
     end
 
     it "should declare itself as closed when it has an error" do
-      pending do
-        TCPSocket.should_receive(:new).and_return(@handle)
-        @socket.open
-        @handle.should_receive(:write).with("fail").and_raise(StandardError)
-        @socket.should be_open
-        lambda { @socket.write("fail") }.should raise_error
-        @socket.should_not be_open
-      end
+      TCPSocket.should_receive(:new).and_return(@handle)
+      @socket.open
+      @handle.should_receive(:write).with("fail").and_raise(StandardError)
+      @socket.should be_open
+      lambda { @socket.write("fail") }.should raise_error
+      @socket.should_not be_open
     end
   end