mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
rb: Ensure the transport is closed if an exception is raised serializing data in Client.send_message [THRIFT-75]
Author: Kevin Ballard <kevin@rapleaf.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@680538 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1f5ce50186
commit
5ebb23b3e1
@ -12,7 +12,12 @@ module Thrift
|
||||
args.each do |k, v|
|
||||
data.send("#{k.to_s}=", v)
|
||||
end
|
||||
data.write(@oprot)
|
||||
begin
|
||||
data.write(@oprot)
|
||||
rescue StandardError => e
|
||||
@oprot.trans.close
|
||||
raise e
|
||||
end
|
||||
@oprot.write_message_end
|
||||
@oprot.trans.flush
|
||||
end
|
||||
|
@ -65,5 +65,17 @@ class ThriftClientSpec < Spec::ExampleGroup
|
||||
end
|
||||
lambda { @client.receive_message(nil) }.should raise_error(StandardError)
|
||||
end
|
||||
|
||||
it "should close the transport if an error occurs while sending a message" do
|
||||
@prot.stub!(:write_message_begin)
|
||||
@prot.should_not_receive(:write_message_end)
|
||||
mock_args = mock("#<TestMessage_args:mock>")
|
||||
mock_args.should_receive(:write).with(@prot).and_raise(StandardError)
|
||||
trans = mock("MockTransport")
|
||||
@prot.stub!(:trans).and_return(trans)
|
||||
trans.should_receive(:close)
|
||||
klass = mock("TestMessage_args", :new => mock_args)
|
||||
lambda { @client.send_message("testMessage", klass) }.should raise_error(StandardError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user