eventmachine 1.0.0.beta.2-x86-mingw32 → 1.0.0.beta.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +3 -0
- data/Gemfile +1 -0
- data/eventmachine.gemspec +1 -3
- data/ext/cmain.cpp +4 -4
- data/ext/ed.cpp +13 -16
- data/ext/ed.h +9 -10
- data/ext/em.cpp +14 -24
- data/ext/eventmachine.h +2 -2
- data/ext/extconf.rb +1 -1
- data/ext/rubymain.cpp +8 -6
- data/lib/em/connection.rb +3 -1
- data/lib/em/pure_ruby.rb +17 -17
- data/lib/em/resolver.rb +186 -0
- data/lib/em/spawnable.rb +3 -7
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +6 -4
- data/lib/jeventmachine.rb +1 -1
- data/tasks/package.rake +4 -1
- data/tasks/test.rake +1 -0
- data/tests/em_test_helper.rb +55 -0
- data/tests/test_attach.rb +46 -56
- data/tests/test_basic.rb +74 -96
- data/tests/test_channel.rb +2 -4
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +13 -44
- data/tests/test_deferrable.rb +19 -19
- data/tests/test_epoll.rb +25 -55
- data/tests/test_error_handler.rb +10 -7
- data/tests/test_exc.rb +6 -33
- data/tests/test_file_watch.rb +51 -35
- data/tests/test_futures.rb +9 -37
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +24 -59
- data/tests/test_httpclient.rb +27 -64
- data/tests/test_httpclient2.rb +1 -29
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +23 -67
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +1 -30
- data/tests/test_object_protocol.rb +8 -9
- data/tests/test_pause.rb +45 -37
- data/tests/test_pending_connect_timeout.rb +42 -38
- data/tests/test_process_watch.rb +1 -3
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +128 -104
- data/tests/test_pure.rb +29 -75
- data/tests/test_queue.rb +2 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +7 -32
- data/tests/test_send_file.rb +162 -196
- data/tests/test_servers.rb +13 -56
- data/tests/test_smtpclient.rb +1 -29
- data/tests/test_smtpserver.rb +1 -29
- data/tests/test_spawn.rb +2 -31
- data/tests/test_ssl_args.rb +9 -10
- data/tests/test_ssl_methods.rb +1 -3
- data/tests/test_ssl_verify.rb +63 -63
- data/tests/test_tick_loop.rb +1 -1
- data/tests/test_timers.rb +52 -89
- data/tests/test_ud.rb +1 -29
- metadata +20 -10
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
data/tests/test_basic.rb
CHANGED
@@ -1,42 +1,18 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 8 April 2006
|
6
|
-
#
|
7
|
-
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
-
# usage examples.
|
9
|
-
#
|
10
|
-
#----------------------------------------------------------------------------
|
11
|
-
#
|
12
|
-
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
-
# Gmail: blackhedd
|
14
|
-
#
|
15
|
-
# This program is free software; you can redistribute it and/or modify
|
16
|
-
# it under the terms of either: 1) the GNU General Public License
|
17
|
-
# as published by the Free Software Foundation; either version 2 of the
|
18
|
-
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
-
#
|
20
|
-
# See the file COPYING for complete licensing information.
|
21
|
-
#
|
22
|
-
#---------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
28
|
-
require 'eventmachine'
|
1
|
+
require 'em_test_helper'
|
29
2
|
require 'socket'
|
30
|
-
require 'test/unit'
|
31
3
|
|
32
4
|
class TestBasic < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@port = next_port
|
7
|
+
end
|
8
|
+
|
33
9
|
def test_connection_class_cache
|
34
10
|
mod = Module.new
|
35
11
|
a, b = nil, nil
|
36
12
|
EM.run {
|
37
|
-
EM.start_server '127.0.0.1',
|
38
|
-
a = EM.connect '127.0.0.1',
|
39
|
-
b = EM.connect '127.0.0.1',
|
13
|
+
EM.start_server '127.0.0.1', @port, mod
|
14
|
+
a = EM.connect '127.0.0.1', @port, mod
|
15
|
+
b = EM.connect '127.0.0.1', @port, mod
|
40
16
|
EM.stop
|
41
17
|
}
|
42
18
|
assert_equal a.class, b.class
|
@@ -47,23 +23,29 @@ class TestBasic < Test::Unit::TestCase
|
|
47
23
|
|
48
24
|
|
49
25
|
def test_em
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
26
|
+
assert_nothing_raised do
|
27
|
+
EM.run {
|
28
|
+
setup_timeout
|
29
|
+
EM.add_timer 0 do
|
30
|
+
EM.stop
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
55
34
|
end
|
56
35
|
|
57
36
|
#-------------------------------------
|
58
37
|
|
59
38
|
def test_timer
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
n
|
64
|
-
|
39
|
+
assert_nothing_raised do
|
40
|
+
EM.run {
|
41
|
+
setup_timeout
|
42
|
+
n = 0
|
43
|
+
EM.add_periodic_timer(0.1) {
|
44
|
+
n += 1
|
45
|
+
EM.stop if n == 2
|
46
|
+
}
|
65
47
|
}
|
66
|
-
|
48
|
+
end
|
67
49
|
end
|
68
50
|
|
69
51
|
#-------------------------------------
|
@@ -71,22 +53,24 @@ class TestBasic < Test::Unit::TestCase
|
|
71
53
|
# This test once threw an already-running exception.
|
72
54
|
module Trivial
|
73
55
|
def post_init
|
74
|
-
|
56
|
+
EM.stop
|
75
57
|
end
|
76
58
|
end
|
77
59
|
|
78
60
|
def test_server
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
61
|
+
assert_nothing_raised do
|
62
|
+
EM.run {
|
63
|
+
setup_timeout
|
64
|
+
EM.start_server "127.0.0.1", @port, Trivial
|
65
|
+
EM.connect "127.0.0.1", @port
|
66
|
+
}
|
67
|
+
end
|
84
68
|
end
|
85
69
|
|
86
70
|
#--------------------------------------
|
87
71
|
|
88
|
-
#
|
89
|
-
# the loop automatically. Contrast with
|
72
|
+
# EM#run_block starts the reactor loop, runs the supplied block, and then STOPS
|
73
|
+
# the loop automatically. Contrast with EM#run, which keeps running the reactor
|
90
74
|
# even after the supplied block completes.
|
91
75
|
def test_run_block
|
92
76
|
assert !EM.reactor_running?
|
@@ -96,9 +80,6 @@ class TestBasic < Test::Unit::TestCase
|
|
96
80
|
assert !EM.reactor_running?
|
97
81
|
end
|
98
82
|
|
99
|
-
TestHost = "127.0.0.1"
|
100
|
-
TestPort = 9070
|
101
|
-
|
102
83
|
class UnbindError < EM::Connection
|
103
84
|
ERR = Class.new(StandardError)
|
104
85
|
def initialize *args
|
@@ -115,8 +96,8 @@ class TestBasic < Test::Unit::TestCase
|
|
115
96
|
def test_unbind_error
|
116
97
|
assert_raises( UnbindError::ERR ) {
|
117
98
|
EM.run {
|
118
|
-
EM.start_server
|
119
|
-
EM.connect
|
99
|
+
EM.start_server "127.0.0.1", @port
|
100
|
+
EM.connect "127.0.0.1", @port, UnbindError
|
120
101
|
}
|
121
102
|
}
|
122
103
|
end
|
@@ -136,22 +117,13 @@ class TestBasic < Test::Unit::TestCase
|
|
136
117
|
end
|
137
118
|
end
|
138
119
|
|
139
|
-
def setup_timeout(timeout = 4)
|
140
|
-
EM.schedule {
|
141
|
-
start_time = EM.current_time
|
142
|
-
EM.add_periodic_timer(0.01) {
|
143
|
-
raise "timeout" if EM.current_time - start_time >= timeout
|
144
|
-
}
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
120
|
# From ticket #50
|
149
121
|
def test_byte_range_send
|
150
122
|
$received = ''
|
151
123
|
$sent = (0..255).to_a.pack('C*')
|
152
124
|
EM::run {
|
153
|
-
EM::start_server
|
154
|
-
EM::connect
|
125
|
+
EM::start_server "127.0.0.1", @port, BrsTestSrv
|
126
|
+
EM::connect "127.0.0.1", @port, BrsTestCli
|
155
127
|
|
156
128
|
setup_timeout
|
157
129
|
}
|
@@ -161,22 +133,27 @@ class TestBasic < Test::Unit::TestCase
|
|
161
133
|
def test_bind_connect
|
162
134
|
local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
|
163
135
|
|
164
|
-
bind_port =
|
136
|
+
bind_port = next_port
|
165
137
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
ensure
|
174
|
-
EM.stop_event_loop
|
175
|
-
end
|
138
|
+
port, ip = nil
|
139
|
+
bound_server = Module.new do
|
140
|
+
define_method :post_init do
|
141
|
+
begin
|
142
|
+
port, ip = Socket.unpack_sockaddr_in(get_peername)
|
143
|
+
ensure
|
144
|
+
EM.stop
|
176
145
|
end
|
177
|
-
end
|
178
|
-
EM.bind_connect local_ip, bind_port, TestHost, TestPort
|
146
|
+
end
|
179
147
|
end
|
148
|
+
|
149
|
+
EM.run do
|
150
|
+
setup_timeout
|
151
|
+
EM.start_server "127.0.0.1", @port, bound_server
|
152
|
+
EM.bind_connect local_ip, bind_port, "127.0.0.1", @port
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_equal bind_port, port
|
156
|
+
assert_equal local_ip, ip
|
180
157
|
end
|
181
158
|
|
182
159
|
def test_reactor_thread?
|
@@ -196,21 +173,24 @@ class TestBasic < Test::Unit::TestCase
|
|
196
173
|
|
197
174
|
def test_schedule_from_thread
|
198
175
|
x = false
|
199
|
-
assert !x
|
200
176
|
EM.run do
|
201
177
|
Thread.new { EM.schedule { x = true; EM.stop } }.join
|
202
178
|
end
|
203
179
|
assert x
|
204
180
|
end
|
205
181
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
EM.
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
182
|
+
if EM.respond_to? :set_heartbeat_interval
|
183
|
+
def test_set_heartbeat_interval
|
184
|
+
interval = 0.5
|
185
|
+
EM.run {
|
186
|
+
EM.set_heartbeat_interval interval
|
187
|
+
$interval = EM.get_heartbeat_interval
|
188
|
+
EM.stop
|
189
|
+
}
|
190
|
+
assert_equal(interval, $interval)
|
191
|
+
end
|
192
|
+
else
|
193
|
+
warn "EM.set_heartbeat_interval not implemented, skipping a test in #{__FILE__}"
|
214
194
|
end
|
215
195
|
|
216
196
|
module PostInitRaiser
|
@@ -221,11 +201,10 @@ class TestBasic < Test::Unit::TestCase
|
|
221
201
|
end
|
222
202
|
|
223
203
|
def test_bubble_errors_from_post_init
|
224
|
-
localhost, port = '127.0.0.1', 9000
|
225
204
|
assert_raises(PostInitRaiser::ERR) do
|
226
205
|
EM.run do
|
227
|
-
EM.start_server
|
228
|
-
EM.connect
|
206
|
+
EM.start_server "127.0.0.1", @port
|
207
|
+
EM.connect "127.0.0.1", @port, PostInitRaiser
|
229
208
|
end
|
230
209
|
end
|
231
210
|
end
|
@@ -238,12 +217,11 @@ class TestBasic < Test::Unit::TestCase
|
|
238
217
|
end
|
239
218
|
|
240
219
|
def test_bubble_errors_from_initialize
|
241
|
-
localhost, port = '127.0.0.1', 9000
|
242
220
|
assert_raises(InitializeRaiser::ERR) do
|
243
221
|
EM.run do
|
244
|
-
EM.start_server
|
245
|
-
EM.connect
|
222
|
+
EM.start_server "127.0.0.1", @port
|
223
|
+
EM.connect "127.0.0.1", @port, InitializeRaiser
|
246
224
|
end
|
247
225
|
end
|
248
226
|
end
|
249
|
-
end
|
227
|
+
end
|
data/tests/test_channel.rb
CHANGED
data/tests/test_defer.rb
CHANGED
@@ -1,49 +1,18 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 8 April 2006
|
6
|
-
#
|
7
|
-
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
-
# usage examples.
|
9
|
-
#
|
10
|
-
#----------------------------------------------------------------------------
|
11
|
-
#
|
12
|
-
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
-
# Gmail: blackhedd
|
14
|
-
#
|
15
|
-
# This program is free software; you can redistribute it and/or modify
|
16
|
-
# it under the terms of either: 1) the GNU General Public License
|
17
|
-
# as published by the Free Software Foundation; either version 2 of the
|
18
|
-
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
-
#
|
20
|
-
# See the file COPYING for complete licensing information.
|
21
|
-
#
|
22
|
-
#---------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
1
|
+
require 'em_test_helper'
|
26
2
|
|
27
|
-
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
3
|
+
class TestDefer < Test::Unit::TestCase
|
30
4
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
work_proc = proc { n += 1 }
|
40
|
-
callback = proc { EM.stop if n == n_times }
|
41
|
-
EM.defer work_proc, callback
|
42
|
-
}
|
5
|
+
def test_defers
|
6
|
+
n = 0
|
7
|
+
n_times = 20
|
8
|
+
EM.run {
|
9
|
+
n_times.times {
|
10
|
+
work_proc = proc { n += 1 }
|
11
|
+
callback = proc { EM.stop if n == n_times }
|
12
|
+
EM.defer work_proc, callback
|
43
13
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
14
|
+
}
|
15
|
+
assert_equal( n, n_times )
|
47
16
|
end
|
48
|
-
end
|
49
17
|
|
18
|
+
end
|
data/tests/test_deferrable.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestDeferrable < Test::Unit::TestCase
|
6
4
|
class Later
|
@@ -8,28 +6,30 @@ class TestDeferrable < Test::Unit::TestCase
|
|
8
6
|
end
|
9
7
|
|
10
8
|
def test_timeout_without_args
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal("none", $args)
|
9
|
+
assert_nothing_raised do
|
10
|
+
EM.run {
|
11
|
+
df = Later.new
|
12
|
+
df.timeout(0)
|
13
|
+
df.errback { EM.stop }
|
14
|
+
EM.add_timer(0.01) { flunk "Deferrable was not timed out." }
|
15
|
+
}
|
16
|
+
end
|
21
17
|
end
|
22
18
|
|
23
19
|
def test_timeout_with_args
|
24
|
-
|
20
|
+
args = nil
|
25
21
|
|
26
22
|
EM.run {
|
27
23
|
df = Later.new
|
28
|
-
df.timeout(0
|
29
|
-
df.errback
|
30
|
-
|
24
|
+
df.timeout(0, :timeout, :foo)
|
25
|
+
df.errback do |type, name|
|
26
|
+
args = [type, name]
|
27
|
+
EM.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
EM.add_timer(0.01) { flunk "Deferrable was not timed out." }
|
31
31
|
}
|
32
32
|
|
33
|
-
assert_equal
|
33
|
+
assert_equal [:timeout, :foo], args
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/tests/test_epoll.rb
CHANGED
@@ -1,35 +1,4 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 8 April 2006
|
6
|
-
#
|
7
|
-
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
-
# usage examples.
|
9
|
-
#
|
10
|
-
#----------------------------------------------------------------------------
|
11
|
-
#
|
12
|
-
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
-
# Gmail: blackhedd
|
14
|
-
#
|
15
|
-
# This program is free software; you can redistribute it and/or modify
|
16
|
-
# it under the terms of either: 1) the GNU General Public License
|
17
|
-
# as published by the Free Software Foundation; either version 2 of the
|
18
|
-
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
-
#
|
20
|
-
# See the file COPYING for complete licensing information.
|
21
|
-
#
|
22
|
-
#---------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# TODO, and I know this doesn't belong here, but if a datagram calls
|
27
|
-
# send_data outside of a receive_data, there is no return address, and
|
28
|
-
# the result is a very confusing error message.
|
29
|
-
#
|
30
|
-
|
31
|
-
require 'eventmachine'
|
32
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
33
2
|
|
34
3
|
|
35
4
|
class TestEpoll < Test::Unit::TestCase
|
@@ -56,16 +25,19 @@ class TestEpoll < Test::Unit::TestCase
|
|
56
25
|
end
|
57
26
|
|
58
27
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
28
|
+
if windows? || jruby?
|
29
|
+
warn "EM.set_descriptor_table_size not implemented, skipping test in #{__FILE__}"
|
30
|
+
else
|
31
|
+
# We can set the rlimit/nofile of a process but we can only set it
|
32
|
+
# higher if we're running as root.
|
33
|
+
# On most systems, the default value is 1024.
|
34
|
+
def test_rlimit
|
35
|
+
unless EM.set_descriptor_table_size >= 1024
|
36
|
+
a = EM.set_descriptor_table_size
|
37
|
+
assert( a <= 1024 )
|
38
|
+
a = EM.set_descriptor_table_size( 1024 )
|
39
|
+
assert( a == 1024 )
|
40
|
+
end
|
69
41
|
end
|
70
42
|
end
|
71
43
|
|
@@ -90,16 +62,9 @@ class TestEpoll < Test::Unit::TestCase
|
|
90
62
|
assert_equal(100, $max)
|
91
63
|
end
|
92
64
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
callback_proc = proc {EM.stop}
|
97
|
-
EM.run {
|
98
|
-
EM.defer work_proc, callback_proc
|
99
|
-
}
|
100
|
-
assert_equal( 1, n )
|
101
|
-
end unless RUBY_VERSION >= '1.9.0'
|
102
|
-
|
65
|
+
def setup
|
66
|
+
@port = next_port
|
67
|
+
end
|
103
68
|
|
104
69
|
module TestDatagramServer
|
105
70
|
def receive_data dgm
|
@@ -108,9 +73,14 @@ class TestEpoll < Test::Unit::TestCase
|
|
108
73
|
end
|
109
74
|
end
|
110
75
|
module TestDatagramClient
|
76
|
+
def initialize port
|
77
|
+
@port = port
|
78
|
+
end
|
79
|
+
|
111
80
|
def post_init
|
112
|
-
send_datagram "1234567890", "127.0.0.1",
|
81
|
+
send_datagram "1234567890", "127.0.0.1", @port
|
113
82
|
end
|
83
|
+
|
114
84
|
def receive_data dgm
|
115
85
|
$out = dgm
|
116
86
|
EM.stop
|
@@ -120,8 +90,8 @@ class TestEpoll < Test::Unit::TestCase
|
|
120
90
|
def test_datagrams
|
121
91
|
$in = $out = ""
|
122
92
|
EM.run {
|
123
|
-
EM.open_datagram_socket "127.0.0.1",
|
124
|
-
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
|
93
|
+
EM.open_datagram_socket "127.0.0.1", @port, TestDatagramServer
|
94
|
+
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient, @port
|
125
95
|
}
|
126
96
|
assert_equal( "1234567890", $in )
|
127
97
|
assert_equal( "abcdefghij", $out )
|