Skip to content
Browse files

correctly pass error to `unbind` on connection handler

  • Loading branch information...
1 parent 69151c3 commit 9943484309743c255e7478eec88764b6fba7d09e @mislav mislav committed Jan 15, 2012
Showing with 20 additions and 3 deletions.
  1. +1 −1 lib/eventmachine.rb
  2. +19 −2 tests/test_unbind_reason.rb
View
2 lib/eventmachine.rb
@@ -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
View
21 tests/test_unbind_reason.rb
@@ -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 {
@@ -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
@@ -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.
Something went wrong with that request. Please try again.