Skip to content

Commit

Permalink
Merge pull request eventmachine#289 from mislav/unbind
Browse files Browse the repository at this point in the history
Correctly pass error to `unbind` on connection handler
  • Loading branch information
tmm1 committed Jan 16, 2012
2 parents 69151c3 + 9943484 commit 64a949a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/eventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ def self.event_callback conn_binding, opcode, data
if opcode == ConnectionUnbound
if c = @conns.delete( conn_binding )
begin
if c.original_method(:unbind).arity == 1
if c.original_method(:unbind).arity != 0
c.unbind(data == 0 ? nil : EventMachine::ERRNOS[data])
else
c.unbind
Expand Down
21 changes: 19 additions & 2 deletions tests/test_unbind_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
require 'socket'

class TestUnbindReason < Test::Unit::TestCase

class StubConnection < EM::Connection
attr_reader :error
def unbind(reason = nil)
@error = reason
EM.stop
end
end

def test_connect_timeout
error = nil
EM.run {
Expand All @@ -13,7 +22,7 @@ def test_connect_timeout
}
conn.pending_connect_timeout = 0.1
}
assert_equal error, Errno::ETIMEDOUT
assert_equal Errno::ETIMEDOUT, error
end

def test_connect_refused
Expand All @@ -26,6 +35,14 @@ def test_connect_refused
end
}
}
assert_equal error, Errno::ECONNREFUSED
assert_equal Errno::ECONNREFUSED, error
end

def test_optional_argument
conn = nil
EM.run {
conn = EM.connect '127.0.0.1', 12388, StubConnection
}
assert_equal Errno::ECONNREFUSED, conn.error
end
end

0 comments on commit 64a949a

Please sign in to comment.