eventmachine 1.2.1-x86-mingw32 → 1.2.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/ext/ed.cpp +3 -2
- data/ext/em.cpp +12 -6
- data/ext/em.h +1 -1
- data/ext/rubymain.cpp +8 -1
- data/lib/1.9/fastfilereaderext.so +0 -0
- data/lib/1.9/rubyeventmachine.so +0 -0
- data/lib/2.0/fastfilereaderext.so +0 -0
- data/lib/2.0/rubyeventmachine.so +0 -0
- data/lib/2.1/fastfilereaderext.so +0 -0
- data/lib/2.1/rubyeventmachine.so +0 -0
- data/lib/2.2/fastfilereaderext.so +0 -0
- data/lib/2.2/rubyeventmachine.so +0 -0
- data/lib/2.3/fastfilereaderext.so +0 -0
- data/lib/2.3/rubyeventmachine.so +0 -0
- data/lib/em/protocols/httpclient.rb +1 -0
- data/lib/em/version.rb +1 -1
- data/lib/jeventmachine.rb +2 -2
- data/tests/test_basic.rb +1 -1
- data/tests/test_connection_count.rb +31 -2
- data/tests/test_file_watch.rb +19 -0
- data/tests/test_httpclient.rb +33 -28
- data/tests/test_httpclient2.rb +26 -26
- data/tests/test_idle_connection.rb +24 -18
- data/tests/test_ipv4.rb +70 -100
- data/tests/test_ipv6.rb +0 -26
- data/tests/test_iterator.rb +19 -16
- data/tests/test_ltp.rb +28 -11
- data/tests/test_pending_connect_timeout.rb +3 -3
- data/tests/test_resolver.rb +4 -3
- data/tests/test_sock_opt.rb +54 -0
- data/tests/test_stomp.rb +11 -10
- data/tests/test_unbind_reason.rb +14 -26
- metadata +4 -6
- data/tests/test_get_sock_opt.rb +0 -37
- data/tests/test_set_sock_opt.rb +0 -39
@@ -1,25 +1,31 @@
|
|
1
1
|
require 'em_test_helper'
|
2
2
|
|
3
3
|
class TestIdleConnection < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
conn.send_data "GET / HTTP/1.0\r\n\r\n"
|
11
|
-
EM.next_tick{
|
12
|
-
EM.next_tick{
|
13
|
-
$idle_time_after_send = conn.get_idle_time
|
14
|
-
conn.close_connection
|
15
|
-
EM.stop
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
4
|
+
def setup
|
5
|
+
@port = next_port
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_idle_time
|
9
|
+
omit_if(!EM.respond_to?(:get_idle_time))
|
20
10
|
|
21
|
-
|
22
|
-
|
11
|
+
a, b = nil, nil
|
12
|
+
EM.run do
|
13
|
+
EM.start_server '127.0.0.1', @port, Module.new
|
14
|
+
conn = EM.connect '127.0.0.1', @port
|
15
|
+
EM.add_timer(0.3) do
|
16
|
+
a = conn.get_idle_time
|
17
|
+
conn.send_data 'a'
|
18
|
+
EM.next_tick do
|
19
|
+
EM.next_tick do
|
20
|
+
b = conn.get_idle_time
|
21
|
+
conn.close_connection
|
22
|
+
EM.stop
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
23
26
|
end
|
27
|
+
|
28
|
+
assert_in_delta 0.3, a, 0.1
|
29
|
+
assert_in_delta 0, b, 0.1
|
24
30
|
end
|
25
31
|
end
|
data/tests/test_ipv4.rb
CHANGED
@@ -1,125 +1,95 @@
|
|
1
1
|
require 'em_test_helper'
|
2
|
-
require 'socket'
|
3
2
|
|
4
3
|
class TestIPv4 < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def c.connection_completed
|
21
|
-
@connected = true
|
22
|
-
EM.stop
|
23
|
-
end
|
4
|
+
# Runs a TCP server in the local IPv4 address, connects to it and sends a specific data.
|
5
|
+
# Timeout in 2 seconds.
|
6
|
+
def test_ipv4_tcp_local_server
|
7
|
+
omit_if(!Test::Unit::TestCase.public_ipv4?)
|
8
|
+
|
9
|
+
@@received_data = nil
|
10
|
+
@local_port = next_port
|
11
|
+
setup_timeout(2)
|
12
|
+
|
13
|
+
EM.run do
|
14
|
+
EM::start_server(@@public_ipv4, @local_port) do |s|
|
15
|
+
def s.receive_data data
|
16
|
+
@@received_data = data
|
17
|
+
EM.stop
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# Runs a TCP server in the local IPv4 address, connects to it and sends a specific data.
|
31
|
-
# Timeout in 2 seconds.
|
32
|
-
def test_ipv4_tcp_local_server
|
33
|
-
@@received_data = nil
|
34
|
-
@local_port = next_port
|
35
|
-
setup_timeout(2)
|
36
|
-
|
37
|
-
EM.run do
|
38
|
-
EM::start_server(@@public_ipv4, @local_port) do |s|
|
39
|
-
def s.receive_data data
|
40
|
-
@@received_data = data
|
41
|
-
EM.stop
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
EM::connect(@@public_ipv4, @local_port) do |c|
|
46
|
-
c.send_data "ipv4/tcp"
|
47
|
-
end
|
21
|
+
EM::connect(@@public_ipv4, @local_port) do |c|
|
22
|
+
c.send_data "ipv4/tcp"
|
48
23
|
end
|
49
|
-
|
50
|
-
assert_equal "ipv4/tcp", @@received_data
|
51
24
|
end
|
52
25
|
|
53
|
-
|
54
|
-
|
55
|
-
def test_ipv4_udp_local_server
|
56
|
-
@@received_data = nil
|
57
|
-
@local_port = next_port
|
58
|
-
setup_timeout(2)
|
59
|
-
|
60
|
-
EM.run do
|
61
|
-
EM::open_datagram_socket(@@public_ipv4, @local_port) do |s|
|
62
|
-
def s.receive_data data
|
63
|
-
@@received_data = data
|
64
|
-
EM.stop
|
65
|
-
end
|
66
|
-
end
|
26
|
+
assert_equal "ipv4/tcp", @@received_data
|
27
|
+
end
|
67
28
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
29
|
+
# Runs a UDP server in the local IPv4 address, connects to it and sends a specific data.
|
30
|
+
# Timeout in 2 seconds.
|
31
|
+
def test_ipv4_udp_local_server
|
32
|
+
omit_if(!Test::Unit::TestCase.public_ipv4?)
|
72
33
|
|
73
|
-
|
74
|
-
|
34
|
+
@@received_data = nil
|
35
|
+
@local_port = next_port
|
36
|
+
setup_timeout(2)
|
75
37
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
EM.run do
|
82
|
-
begin
|
83
|
-
error = nil
|
84
|
-
EM.connect(invalid_ipv4, 1234)
|
85
|
-
rescue => e
|
86
|
-
error = e
|
87
|
-
ensure
|
38
|
+
EM.run do
|
39
|
+
EM::open_datagram_socket(@@public_ipv4, @local_port) do |s|
|
40
|
+
def s.receive_data data
|
41
|
+
@@received_data = data
|
88
42
|
EM.stop
|
89
|
-
assert_equal EM::ConnectionError, (error && error.class)
|
90
43
|
end
|
91
44
|
end
|
45
|
+
|
46
|
+
EM::open_datagram_socket(@@public_ipv4, next_port) do |c|
|
47
|
+
c.send_datagram "ipv4/udp", @@public_ipv4, @local_port
|
48
|
+
end
|
92
49
|
end
|
93
50
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
51
|
+
assert_equal "ipv4/udp", @@received_data
|
52
|
+
end
|
53
|
+
|
54
|
+
# Try to connect via TCP to an invalid IPv4. EM.connect should raise
|
55
|
+
# EM::ConnectionError.
|
56
|
+
def test_tcp_connect_to_invalid_ipv4
|
57
|
+
omit_if(!Test::Unit::TestCase.public_ipv4?)
|
58
|
+
|
59
|
+
invalid_ipv4 = "9.9:9"
|
60
|
+
|
61
|
+
EM.run do
|
62
|
+
begin
|
63
|
+
error = nil
|
64
|
+
EM.connect(invalid_ipv4, 1234)
|
65
|
+
rescue => e
|
66
|
+
error = e
|
67
|
+
ensure
|
68
|
+
EM.stop
|
69
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
111
70
|
end
|
112
71
|
end
|
72
|
+
end
|
113
73
|
|
74
|
+
# Try to send a UDP datagram to an invalid IPv4. EM.send_datagram should raise
|
75
|
+
# EM::ConnectionError.
|
76
|
+
def test_udp_send_datagram_to_invalid_ipv4
|
77
|
+
omit_if(!Test::Unit::TestCase.public_ipv4?)
|
114
78
|
|
115
|
-
|
116
|
-
warn "no IPv4 in this host, skipping tests in #{__FILE__}"
|
79
|
+
invalid_ipv4 = "9.9:9"
|
117
80
|
|
118
|
-
|
119
|
-
|
120
|
-
|
81
|
+
EM.run do
|
82
|
+
begin
|
83
|
+
error = nil
|
84
|
+
EM.open_datagram_socket(@@public_ipv4, next_port) do |c|
|
85
|
+
c.send_datagram "hello", invalid_ipv4, 1234
|
86
|
+
end
|
87
|
+
rescue => e
|
88
|
+
error = e
|
89
|
+
ensure
|
90
|
+
EM.stop
|
91
|
+
assert_equal EM::ConnectionError, (error && error.class)
|
92
|
+
end
|
121
93
|
end
|
122
|
-
|
123
94
|
end
|
124
|
-
|
125
95
|
end
|
data/tests/test_ipv6.rb
CHANGED
@@ -4,32 +4,6 @@ class TestIPv6 < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
if Test::Unit::TestCase.public_ipv6?
|
6
6
|
|
7
|
-
# Tries to connect to ipv6.google.com (2607:f8b0:4010:800::1006) port 80 via TCP.
|
8
|
-
# Timeout in 6 seconds.
|
9
|
-
def test_ipv6_tcp_client_with_ipv6_google_com
|
10
|
-
conn = nil
|
11
|
-
setup_timeout(6)
|
12
|
-
|
13
|
-
EM.run do
|
14
|
-
conn = EM::connect("2607:f8b0:4010:800::1006", 80) do |c|
|
15
|
-
def c.connected
|
16
|
-
@connected
|
17
|
-
end
|
18
|
-
|
19
|
-
def c.unbind(reason)
|
20
|
-
warn "unbind: #{reason.inspect}" if reason # XXX at least find out why it failed
|
21
|
-
end
|
22
|
-
|
23
|
-
def c.connection_completed
|
24
|
-
@connected = true
|
25
|
-
EM.stop
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
assert conn.connected
|
31
|
-
end
|
32
|
-
|
33
7
|
# Runs a TCP server in the local IPv6 address, connects to it and sends a specific data.
|
34
8
|
# Timeout in 2 seconds.
|
35
9
|
def test_ipv6_tcp_local_server
|
data/tests/test_iterator.rb
CHANGED
@@ -2,8 +2,12 @@ require 'em_test_helper'
|
|
2
2
|
|
3
3
|
class TestIterator < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# By default, format the time with tenths-of-seconds.
|
6
|
+
# Some tests should ask for extra decimal places to ensure
|
7
|
+
# that delays between iterations will receive a changed time.
|
8
|
+
def get_time(n=1)
|
9
|
+
time = EM.current_time
|
10
|
+
time.strftime('%H:%M:%S.') + time.tv_usec.to_s[0, n]
|
7
11
|
end
|
8
12
|
|
9
13
|
def test_default_concurrency
|
@@ -11,10 +15,10 @@ class TestIterator < Test::Unit::TestCase
|
|
11
15
|
list = 1..10
|
12
16
|
EM.run {
|
13
17
|
EM::Iterator.new(list).each( proc {|num,iter|
|
14
|
-
time = get_time
|
18
|
+
time = get_time(3)
|
15
19
|
items[time] ||= []
|
16
20
|
items[time] << num
|
17
|
-
EM::Timer.new(
|
21
|
+
EM::Timer.new(0.02) {iter.next}
|
18
22
|
}, proc {EM.stop})
|
19
23
|
}
|
20
24
|
assert_equal(10, items.keys.size)
|
@@ -27,10 +31,10 @@ class TestIterator < Test::Unit::TestCase
|
|
27
31
|
original_list = list.dup
|
28
32
|
EM.run {
|
29
33
|
EM::Iterator.new(proc{list.pop || EM::Iterator::Stop}).each( proc {|num,iter|
|
30
|
-
time = get_time
|
34
|
+
time = get_time(3)
|
31
35
|
items[time] ||= []
|
32
36
|
items[time] << num
|
33
|
-
EM::Timer.new(
|
37
|
+
EM::Timer.new(0.02) {iter.next}
|
34
38
|
}, proc {EM.stop})
|
35
39
|
}
|
36
40
|
assert_equal(10, items.keys.size)
|
@@ -52,26 +56,25 @@ class TestIterator < Test::Unit::TestCase
|
|
52
56
|
assert_equal(list.to_a.sort, items.values.flatten.sort)
|
53
57
|
end
|
54
58
|
|
55
|
-
|
56
59
|
def test_changing_concurrency_affects_active_iteration
|
57
60
|
items = {}
|
58
61
|
list = 1..25
|
62
|
+
seen = 0
|
59
63
|
EM.run {
|
60
|
-
i = EM::Iterator.new(list,
|
64
|
+
i = EM::Iterator.new(list,1)
|
61
65
|
i.each(proc {|num,iter|
|
62
66
|
time = get_time
|
63
67
|
items[time] ||= []
|
64
68
|
items[time] << num
|
65
|
-
|
69
|
+
if (seen += 1) == 5
|
70
|
+
# The first 5 items will be distinct times
|
71
|
+
# The next 20 items will happen in 2 bursts
|
72
|
+
i.concurrency = 10
|
73
|
+
end
|
74
|
+
EM::Timer.new(0.2) {iter.next}
|
66
75
|
}, proc {EM.stop})
|
67
|
-
EM.add_timer(1){
|
68
|
-
i.concurrency = 1
|
69
|
-
}
|
70
|
-
EM.add_timer(3){
|
71
|
-
i.concurrency = 3
|
72
|
-
}
|
73
76
|
}
|
74
|
-
|
77
|
+
assert_in_delta(7, items.keys.size, 1)
|
75
78
|
assert_equal(list.to_a.sort, items.values.flatten.sort)
|
76
79
|
end
|
77
80
|
|
data/tests/test_ltp.rb
CHANGED
@@ -2,7 +2,14 @@ require 'em_test_helper'
|
|
2
2
|
|
3
3
|
class TestLineAndTextProtocol < Test::Unit::TestCase
|
4
4
|
|
5
|
-
class
|
5
|
+
class TLP_LineBuffer < EM::P::LineAndTextProtocol
|
6
|
+
attr_reader :line_buffer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@line_buffer = []
|
11
|
+
end
|
12
|
+
|
6
13
|
def receive_line line
|
7
14
|
@line_buffer << line
|
8
15
|
end
|
@@ -27,10 +34,10 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
27
34
|
end
|
28
35
|
|
29
36
|
def test_simple_lines
|
30
|
-
|
37
|
+
conn = nil
|
31
38
|
EM.run {
|
32
|
-
EM.start_server( "127.0.0.1", @port,
|
33
|
-
conn
|
39
|
+
EM.start_server( "127.0.0.1", @port, TLP_LineBuffer ) do |c|
|
40
|
+
conn = c
|
34
41
|
end
|
35
42
|
setup_timeout
|
36
43
|
|
@@ -39,25 +46,35 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
39
46
|
c.close_connection_after_writing
|
40
47
|
end
|
41
48
|
}
|
42
|
-
assert_equal( %w(aaa bbb ccc),
|
49
|
+
assert_equal( %w(aaa bbb ccc), conn.line_buffer)
|
43
50
|
end
|
44
51
|
|
45
52
|
#--------------------------------------------------------------------
|
46
53
|
|
47
|
-
class
|
54
|
+
class TLP_ErrorMessage < EM::P::LineAndTextProtocol
|
55
|
+
attr_reader :error_message
|
56
|
+
|
57
|
+
def initialize
|
58
|
+
super
|
59
|
+
@error_message = []
|
60
|
+
end
|
61
|
+
|
62
|
+
def receive_line text
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
|
48
66
|
def receive_error text
|
49
67
|
@error_message << text
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
53
71
|
def test_overlength_lines
|
54
|
-
|
72
|
+
conn = nil
|
55
73
|
EM.run {
|
56
|
-
EM.start_server( "127.0.0.1", @port,
|
57
|
-
conn
|
74
|
+
EM.start_server( "127.0.0.1", @port, TLP_ErrorMessage ) do |c|
|
75
|
+
conn = c
|
58
76
|
end
|
59
77
|
setup_timeout
|
60
|
-
|
61
78
|
EM.connect "127.0.0.1", @port, StopClient do |c|
|
62
79
|
c.send_data "a" * (16*1024 + 1)
|
63
80
|
c.send_data "\n"
|
@@ -65,7 +82,7 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
65
82
|
end
|
66
83
|
|
67
84
|
}
|
68
|
-
assert_equal( ["overlength line"],
|
85
|
+
assert_equal( ["overlength line"], conn.error_message )
|
69
86
|
end
|
70
87
|
|
71
88
|
|
@@ -25,7 +25,7 @@ class TestPendingConnectTimeout < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
timeout_handler = Module.new do
|
27
27
|
define_method :unbind do
|
28
|
-
finish =
|
28
|
+
finish = EM.current_time
|
29
29
|
EM.stop
|
30
30
|
end
|
31
31
|
end
|
@@ -33,8 +33,8 @@ class TestPendingConnectTimeout < Test::Unit::TestCase
|
|
33
33
|
EM.run {
|
34
34
|
setup_timeout
|
35
35
|
EM.heartbeat_interval = 0.1
|
36
|
-
start =
|
37
|
-
c = EM.connect(
|
36
|
+
start = EM.current_time
|
37
|
+
c = EM.connect('192.0.2.0', 54321, timeout_handler)
|
38
38
|
c.pending_connect_timeout = 0.2
|
39
39
|
}
|
40
40
|
|