forked from eventmachine/eventmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unbind_reason.rb
48 lines (43 loc) · 1019 Bytes
/
test_unbind_reason.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'em_test_helper'
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 {
conn = EM.connect 'google.com', 81, Module.new{ |m|
m.send(:define_method, :unbind) do |reason|
error = reason
EM.stop
end
}
conn.pending_connect_timeout = 0.1
}
assert_equal Errno::ETIMEDOUT, error
end
def test_connect_refused
error = nil
EM.run {
EM.connect '127.0.0.1', 12388, Module.new{ |m|
m.send(:define_method, :unbind) do |reason|
error = reason
EM.stop
end
}
}
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