Skip to content

Commit

Permalink
correctly pass error to unbind on connection handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jan 15, 2012
1 parent 69151c3 commit 9943484
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 9943484

Please sign in to comment.