From 9943484309743c255e7478eec88764b6fba7d09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Sun, 15 Jan 2012 17:50:51 +0100 Subject: [PATCH] correctly pass error to `unbind` on connection handler --- lib/eventmachine.rb | 2 +- tests/test_unbind_reason.rb | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/eventmachine.rb b/lib/eventmachine.rb index 15f95d3f3..4fb1b7df3 100644 --- a/lib/eventmachine.rb +++ b/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 diff --git a/tests/test_unbind_reason.rb b/tests/test_unbind_reason.rb index dafcdc99f..72a99f55f 100644 --- a/tests/test_unbind_reason.rb +++ b/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