Skip to content

Commit e3599ba

Browse files
Add a test for failure.
1 parent 629b5f7 commit e3599ba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/async/container/supervisor/connection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def write(**message)
251251
#
252252
# @parameter timeout [Numeric, nil] Optional timeout for the call.
253253
# @parameter message [Hash] The call message.
254+
# @raises [IOError | Errno::EPIPE | Errno::ECONNRESET] If the write fails.
254255
# @returns [Hash] The response.
255256
def call(timeout: nil, **message)
256257
id = next_id

test/async/container/connection.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def dispatch(call)
2121
let(:connection) {Async::Container::Supervisor::Connection.new(stream)}
2222

2323
with "dispatch" do
24-
it "handles failed writes" do
24+
it "handles failed writes when dispatching a call" do
2525
stream.write(JSON.dump({id: 1, do: :test}) << "\n")
2626
stream.rewind
2727

@@ -39,6 +39,16 @@ def dispatch(call)
3939

4040
expect(connection.calls).to be(:empty?)
4141
end
42+
43+
it "handles failed writes when making a call" do
44+
expect(stream).to receive(:write).and_raise(IOError, "Test error")
45+
46+
expect do
47+
connection.call(do: :test)
48+
end.to raise_exception(IOError, message: be =~ /Test error/)
49+
50+
expect(connection.calls).to be(:empty?)
51+
end
4252
end
4353

4454
with subject::Call do

0 commit comments

Comments
 (0)