eventmachine 1.2.0.dev.2-x64-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +105 -0
- data/GNU +281 -0
- data/LICENSE +60 -0
- data/README.md +108 -0
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/ChangeLog +211 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/old/EPOLL +141 -0
- data/docs/old/INSTALL +13 -0
- data/docs/old/KEYBOARD +42 -0
- data/docs/old/LEGAL +25 -0
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/PURE_RUBY +75 -0
- data/docs/old/RELEASE_NOTES +94 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/docs/old/TODO +8 -0
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/old/ex_channel.rb +43 -0
- data/examples/old/ex_queue.rb +2 -0
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/examples/old/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +988 -0
- data/ext/ed.cpp +2111 -0
- data/ext/ed.h +442 -0
- data/ext/em.cpp +2379 -0
- data/ext/em.h +308 -0
- data/ext/eventmachine.h +143 -0
- data/ext/extconf.rb +270 -0
- data/ext/fastfilereader/extconf.rb +110 -0
- data/ext/fastfilereader/mapper.cpp +216 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +354 -0
- data/ext/project.h +176 -0
- data/ext/rubymain.cpp +1504 -0
- data/ext/ssl.cpp +615 -0
- data/ext/ssl.h +103 -0
- data/java/.classpath +8 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +591 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -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/buftok.rb +59 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +69 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +770 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +252 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +299 -0
- data/lib/em/protocols/httpclient2.rb +600 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/linetext2.rb +166 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +394 -0
- data/lib/em/protocols/smtpserver.rb +666 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +205 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/pure_ruby.rb +1022 -0
- data/lib/em/queue.rb +80 -0
- data/lib/em/resolver.rb +232 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +61 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1584 -0
- data/lib/fastfilereaderext.rb +2 -0
- data/lib/jeventmachine.rb +301 -0
- data/lib/rubyeventmachine.rb +2 -0
- data/rakelib/package.rake +120 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/dhparam.pem +13 -0
- data/tests/em_test_helper.rb +151 -0
- data/tests/test_attach.rb +151 -0
- data/tests/test_basic.rb +283 -0
- data/tests/test_channel.rb +75 -0
- data/tests/test_completion.rb +178 -0
- data/tests/test_connection_count.rb +54 -0
- data/tests/test_connection_write.rb +35 -0
- data/tests/test_defer.rb +35 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +142 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +66 -0
- data/tests/test_fork.rb +75 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_get_sock_opt.rb +37 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +233 -0
- data/tests/test_httpclient2.rb +128 -0
- data/tests/test_idle_connection.rb +25 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_ipv4.rb +125 -0
- data/tests/test_ipv6.rb +131 -0
- data/tests/test_iterator.rb +115 -0
- data/tests/test_kb.rb +28 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +308 -0
- data/tests/test_many_fds.rb +22 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +107 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +196 -0
- data/tests/test_process_watch.rb +50 -0
- data/tests/test_processes.rb +128 -0
- data/tests/test_proxy_connection.rb +180 -0
- data/tests/test_pure.rb +88 -0
- data/tests/test_queue.rb +64 -0
- data/tests/test_resolver.rb +104 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +47 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +33 -0
- data/tests/test_set_sock_opt.rb +39 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +75 -0
- data/tests/test_smtpserver.rb +57 -0
- data/tests/test_spawn.rb +293 -0
- data/tests/test_ssl_args.rb +78 -0
- data/tests/test_ssl_dhparam.rb +83 -0
- data/tests/test_ssl_ecdh_curve.rb +79 -0
- data/tests/test_ssl_extensions.rb +49 -0
- data/tests/test_ssl_methods.rb +65 -0
- data/tests/test_ssl_protocols.rb +246 -0
- data/tests/test_ssl_verify.rb +126 -0
- data/tests/test_stomp.rb +37 -0
- data/tests/test_system.rb +46 -0
- data/tests/test_threaded_resource.rb +61 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +123 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_unbind_reason.rb +52 -0
- metadata +381 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestEMChannel < Test::Unit::TestCase
|
4
|
+
def test_channel_subscribe
|
5
|
+
s = 0
|
6
|
+
EM.run do
|
7
|
+
c = EM::Channel.new
|
8
|
+
c.subscribe { |v| s = v; EM.stop }
|
9
|
+
c << 1
|
10
|
+
end
|
11
|
+
assert_equal 1, s
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_channel_unsubscribe
|
15
|
+
s = 0
|
16
|
+
EM.run do
|
17
|
+
c = EM::Channel.new
|
18
|
+
subscription = c.subscribe { |v| s = v }
|
19
|
+
c.unsubscribe(subscription)
|
20
|
+
c << 1
|
21
|
+
EM.next_tick { EM.stop }
|
22
|
+
end
|
23
|
+
assert_not_equal 1, s
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_channel_pop
|
27
|
+
s = 0
|
28
|
+
EM.run do
|
29
|
+
c = EM::Channel.new
|
30
|
+
c.pop{ |v| s = v }
|
31
|
+
c.push(1,2,3)
|
32
|
+
c << 4
|
33
|
+
c << 5
|
34
|
+
EM.next_tick { EM.stop }
|
35
|
+
end
|
36
|
+
assert_equal 1, s
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_channel_reactor_thread_push
|
40
|
+
out = []
|
41
|
+
c = EM::Channel.new
|
42
|
+
c.subscribe { |v| out << v }
|
43
|
+
Thread.new { c.push(1,2,3) }.join
|
44
|
+
assert out.empty?
|
45
|
+
|
46
|
+
EM.run { EM.next_tick { EM.stop } }
|
47
|
+
|
48
|
+
assert_equal [1,2,3], out
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_channel_reactor_thread_callback
|
52
|
+
out = []
|
53
|
+
c = EM::Channel.new
|
54
|
+
Thread.new { c.subscribe { |v| out << v } }.join
|
55
|
+
c.push(1,2,3)
|
56
|
+
assert out.empty?
|
57
|
+
|
58
|
+
EM.run { EM.next_tick { EM.stop } }
|
59
|
+
|
60
|
+
assert_equal [1,2,3], out
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_channel_num_subscribers
|
64
|
+
subs = 0
|
65
|
+
EM.run do
|
66
|
+
c = EM::Channel.new
|
67
|
+
c.subscribe { |v| s = v }
|
68
|
+
c.subscribe { |v| s = v }
|
69
|
+
EM.next_tick { EM.stop }
|
70
|
+
subs = c.num_subscribers
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_equal subs, 2
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'em/completion'
|
3
|
+
|
4
|
+
class TestCompletion < Test::Unit::TestCase
|
5
|
+
def completion
|
6
|
+
@completion ||= EM::Completion.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def crank
|
10
|
+
# This is a slow solution, but this just executes the next tick queue
|
11
|
+
# once. It's the easiest way for now.
|
12
|
+
EM.run { EM.stop }
|
13
|
+
end
|
14
|
+
|
15
|
+
def results
|
16
|
+
@results ||= []
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_state
|
20
|
+
assert_equal :unknown, completion.state
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_succeed
|
24
|
+
completion.callback { |val| results << val }
|
25
|
+
completion.succeed :object
|
26
|
+
crank
|
27
|
+
assert_equal :succeeded, completion.state
|
28
|
+
assert_equal [:object], results
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_fail
|
32
|
+
completion.errback { |val| results << val }
|
33
|
+
completion.fail :object
|
34
|
+
crank
|
35
|
+
assert_equal :failed, completion.state
|
36
|
+
assert_equal [:object], results
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_callback
|
40
|
+
completion.callback { results << :callback }
|
41
|
+
completion.errback { results << :errback }
|
42
|
+
completion.succeed
|
43
|
+
crank
|
44
|
+
assert_equal [:callback], results
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_errback
|
48
|
+
completion.callback { results << :callback }
|
49
|
+
completion.errback { results << :errback }
|
50
|
+
completion.fail
|
51
|
+
crank
|
52
|
+
assert_equal [:errback], results
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_stateback
|
56
|
+
completion.stateback(:magic) { results << :stateback }
|
57
|
+
completion.change_state(:magic)
|
58
|
+
crank
|
59
|
+
assert_equal [:stateback], results
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_does_not_enqueue_when_completed
|
63
|
+
completion.callback { results << :callback }
|
64
|
+
completion.succeed
|
65
|
+
completion.errback { results << :errback }
|
66
|
+
completion.fail
|
67
|
+
crank
|
68
|
+
assert_equal [:callback], results
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_completed
|
72
|
+
assert_equal false, completion.completed?
|
73
|
+
completion.succeed
|
74
|
+
assert_equal true, completion.completed?
|
75
|
+
completion.fail
|
76
|
+
assert_equal true, completion.completed?
|
77
|
+
completion.change_state :magic
|
78
|
+
assert_equal false, completion.completed?
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_recursive_callbacks
|
82
|
+
completion.callback do |val|
|
83
|
+
results << val
|
84
|
+
completion.succeed :two
|
85
|
+
end
|
86
|
+
completion.callback do |val|
|
87
|
+
results << val
|
88
|
+
completion.succeed :three
|
89
|
+
end
|
90
|
+
completion.callback do |val|
|
91
|
+
results << val
|
92
|
+
end
|
93
|
+
completion.succeed :one
|
94
|
+
crank
|
95
|
+
assert_equal [:one, :two, :three], results
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_late_defined_callbacks
|
99
|
+
completion.callback { results << :one }
|
100
|
+
completion.succeed
|
101
|
+
crank
|
102
|
+
assert_equal [:one], results
|
103
|
+
completion.callback { results << :two }
|
104
|
+
crank
|
105
|
+
assert_equal [:one, :two], results
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_cleared_completions
|
109
|
+
completion.callback { results << :callback }
|
110
|
+
completion.errback { results << :errback }
|
111
|
+
|
112
|
+
completion.succeed
|
113
|
+
crank
|
114
|
+
completion.fail
|
115
|
+
crank
|
116
|
+
completion.succeed
|
117
|
+
crank
|
118
|
+
|
119
|
+
assert_equal [:callback], results
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_skip_completed_callbacks
|
123
|
+
completion.callback { results << :callback }
|
124
|
+
completion.succeed
|
125
|
+
crank
|
126
|
+
|
127
|
+
completion.errback { results << :errback }
|
128
|
+
completion.fail
|
129
|
+
crank
|
130
|
+
|
131
|
+
assert_equal [:callback], results
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_completions
|
135
|
+
completion.completion { results << :completion }
|
136
|
+
completion.succeed
|
137
|
+
crank
|
138
|
+
assert_equal [:completion], results
|
139
|
+
|
140
|
+
completion.change_state(:unknown)
|
141
|
+
results.clear
|
142
|
+
|
143
|
+
completion.completion { results << :completion }
|
144
|
+
completion.fail
|
145
|
+
crank
|
146
|
+
assert_equal [:completion], results
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_latent_completion
|
150
|
+
completion.completion { results << :completion }
|
151
|
+
completion.succeed
|
152
|
+
crank
|
153
|
+
completion.completion { results << :completion }
|
154
|
+
crank
|
155
|
+
assert_equal [:completion, :completion], results
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_timeout
|
159
|
+
args = [1, 2, 3]
|
160
|
+
EM.run do
|
161
|
+
completion.timeout(0.0001, *args)
|
162
|
+
completion.errback { |*errargs| results << errargs }
|
163
|
+
completion.completion { EM.stop }
|
164
|
+
EM.add_timer(0.1) { flunk 'test timed out' }
|
165
|
+
end
|
166
|
+
assert_equal [[1,2,3]], results
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_timeout_gets_cancelled
|
170
|
+
EM.run do
|
171
|
+
completion.timeout(0.0001, :timeout)
|
172
|
+
completion.errback { results << :errback }
|
173
|
+
completion.succeed
|
174
|
+
EM.add_timer(0.0002) { EM.stop }
|
175
|
+
end
|
176
|
+
assert_equal [], results
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestConnectionCount < Test::Unit::TestCase
|
4
|
+
def test_idle_connection_count
|
5
|
+
EM.run {
|
6
|
+
$count = EM.connection_count
|
7
|
+
EM.stop_event_loop
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_equal(0, $count)
|
11
|
+
end
|
12
|
+
|
13
|
+
module Client
|
14
|
+
def connection_completed
|
15
|
+
$client_conns += 1
|
16
|
+
EM.stop if $client_conns == 3
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_with_some_connections
|
21
|
+
EM.run {
|
22
|
+
$client_conns = 0
|
23
|
+
$initial_conns = EM.connection_count
|
24
|
+
EM.start_server("127.0.0.1", 9999)
|
25
|
+
$server_conns = EM.connection_count
|
26
|
+
3.times { EM.connect("127.0.0.1", 9999, Client) }
|
27
|
+
}
|
28
|
+
|
29
|
+
assert_equal(0, $initial_conns)
|
30
|
+
assert_equal(1, $server_conns)
|
31
|
+
assert_equal(4, $client_conns + $server_conns)
|
32
|
+
end
|
33
|
+
|
34
|
+
module DoubleCloseClient
|
35
|
+
def unbind
|
36
|
+
close_connection
|
37
|
+
$num_close_scheduled_1 = EM.num_close_scheduled
|
38
|
+
EM.next_tick do
|
39
|
+
$num_close_scheduled_2 = EM.num_close_scheduled
|
40
|
+
EM.stop
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_num_close_scheduled
|
46
|
+
omit_if(jruby?)
|
47
|
+
EM.run {
|
48
|
+
assert_equal(0, EM.num_close_scheduled)
|
49
|
+
EM.connect("127.0.0.1", 9999, DoubleCloseClient) # nothing listening on 9999
|
50
|
+
}
|
51
|
+
assert_equal(1, $num_close_scheduled_1)
|
52
|
+
assert_equal(0, $num_close_scheduled_2)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestConnectionWrite < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# This test takes advantage of the fact that EM::_RunSelectOnce iterates over the connections twice:
|
6
|
+
# - once to determine which ones to call Write() on
|
7
|
+
# - and once to call Write() on each of them.
|
8
|
+
#
|
9
|
+
# But state may change in the meantime before Write() is finally called.
|
10
|
+
# And that is what we try to exploit to get Write() to be called when bWatchOnly is true, and bNotifyWritable is false,
|
11
|
+
# to cause an assertion failure.
|
12
|
+
|
13
|
+
module SimpleClient
|
14
|
+
def notify_writable
|
15
|
+
$conn2.notify_writable = false # Being naughty in callback
|
16
|
+
# If this doesn't crash anything, the test passed!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_with_naughty_callback
|
21
|
+
EM.run do
|
22
|
+
r1, _ = IO.pipe
|
23
|
+
r2, _ = IO.pipe
|
24
|
+
|
25
|
+
# Adding EM.watches
|
26
|
+
$conn1 = EM.watch(r1, SimpleClient)
|
27
|
+
$conn2 = EM.watch(r2, SimpleClient)
|
28
|
+
|
29
|
+
$conn1.notify_writable = true
|
30
|
+
$conn2.notify_writable = true
|
31
|
+
|
32
|
+
EM.stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/tests/test_defer.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestDefer < Test::Unit::TestCase
|
4
|
+
|
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
|
13
|
+
}
|
14
|
+
}
|
15
|
+
assert_equal( n, n_times )
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_errbacks
|
19
|
+
iterations = 20
|
20
|
+
callback_parameter = rand(100)
|
21
|
+
callback_parameters = []
|
22
|
+
callback_op = proc { callback_parameter }
|
23
|
+
callback = proc { |result| callback_parameters << result }
|
24
|
+
errback_parameter = Exception.new
|
25
|
+
errback_parameters = []
|
26
|
+
errback_op = proc { raise errback_parameter }
|
27
|
+
errback = proc { |error| errback_parameters << error }
|
28
|
+
EventMachine.run do
|
29
|
+
(1..iterations).each { |index| EventMachine.defer(index.even? ? callback_op : errback_op, callback, errback) }
|
30
|
+
EventMachine.add_periodic_timer(0.1) { EventMachine.stop if EventMachine.defers_finished? }
|
31
|
+
end
|
32
|
+
assert_equal(callback_parameters.select { |parameter| parameter == callback_parameter }.length, iterations * 0.5)
|
33
|
+
assert_equal(errback_parameters.select{ |parameter| parameter == errback_parameter }.length, iterations * 0.5)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestDeferrable < Test::Unit::TestCase
|
4
|
+
class Later
|
5
|
+
include EM::Deferrable
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_timeout_without_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
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_timeout_with_args
|
20
|
+
args = nil
|
21
|
+
|
22
|
+
EM.run {
|
23
|
+
df = Later.new
|
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
|
+
}
|
32
|
+
|
33
|
+
assert_equal [:timeout, :foo], args
|
34
|
+
end
|
35
|
+
end
|
data/tests/test_epoll.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class TestEpoll < Test::Unit::TestCase
|
5
|
+
|
6
|
+
module TestEchoServer
|
7
|
+
def receive_data data
|
8
|
+
send_data data
|
9
|
+
close_connection_after_writing
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module TestEchoClient
|
14
|
+
def connection_completed
|
15
|
+
send_data "ABCDE"
|
16
|
+
$max += 1
|
17
|
+
end
|
18
|
+
def receive_data data
|
19
|
+
raise "bad response" unless data == "ABCDE"
|
20
|
+
end
|
21
|
+
def unbind
|
22
|
+
$n -= 1
|
23
|
+
EM.stop if $n == 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# We can set the rlimit/nofile of a process but we can only set it
|
29
|
+
# higher if we're running as root.
|
30
|
+
# On most systems, the default value is 1024.
|
31
|
+
def test_rlimit
|
32
|
+
omit_if(windows? || jruby?)
|
33
|
+
unless EM.set_descriptor_table_size >= 1024
|
34
|
+
a = EM.set_descriptor_table_size
|
35
|
+
assert( a <= 1024 )
|
36
|
+
a = EM.set_descriptor_table_size( 1024 )
|
37
|
+
assert( a == 1024 )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Run a high-volume version of this test by kicking the number of connections
|
42
|
+
# up past 512. (Each connection uses two sockets, a client and a server.)
|
43
|
+
# (Will require running the test as root)
|
44
|
+
# This test exercises TCP clients and servers.
|
45
|
+
#
|
46
|
+
# XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
|
47
|
+
def _test_descriptors
|
48
|
+
EM.epoll
|
49
|
+
EM.set_descriptor_table_size 60000
|
50
|
+
EM.run {
|
51
|
+
EM.start_server "127.0.0.1", 9800, TestEchoServer
|
52
|
+
$n = 0
|
53
|
+
$max = 0
|
54
|
+
100.times {
|
55
|
+
EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
assert_equal(0, $n)
|
59
|
+
assert_equal(100, $max)
|
60
|
+
end
|
61
|
+
|
62
|
+
def setup
|
63
|
+
@port = next_port
|
64
|
+
end
|
65
|
+
|
66
|
+
module TestDatagramServer
|
67
|
+
def receive_data dgm
|
68
|
+
$in = dgm
|
69
|
+
send_data "abcdefghij"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
module TestDatagramClient
|
73
|
+
def initialize port
|
74
|
+
@port = port
|
75
|
+
end
|
76
|
+
|
77
|
+
def post_init
|
78
|
+
send_datagram "1234567890", "127.0.0.1", @port
|
79
|
+
end
|
80
|
+
|
81
|
+
def receive_data dgm
|
82
|
+
$out = dgm
|
83
|
+
EM.stop
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_datagrams
|
88
|
+
$in = $out = ""
|
89
|
+
EM.run {
|
90
|
+
EM.open_datagram_socket "127.0.0.1", @port, TestDatagramServer
|
91
|
+
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient, @port
|
92
|
+
}
|
93
|
+
assert_equal( "1234567890", $in )
|
94
|
+
assert_equal( "abcdefghij", $out )
|
95
|
+
end
|
96
|
+
|
97
|
+
# XXX this test fails randomly...
|
98
|
+
def _test_unix_domain
|
99
|
+
fn = "/tmp/xxx.chain"
|
100
|
+
EM.epoll
|
101
|
+
EM.set_descriptor_table_size 60000
|
102
|
+
EM.run {
|
103
|
+
# The pure-Ruby version won't let us open the socket if the node already exists.
|
104
|
+
# Not sure, that actually may be correct and the compiled version is wrong.
|
105
|
+
# Pure Ruby also oddly won't let us make that many connections. This test used
|
106
|
+
# to run 100 times. Not sure where that lower connection-limit is coming from in
|
107
|
+
# pure Ruby.
|
108
|
+
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
|
109
|
+
# work on Windows anyway.
|
110
|
+
#
|
111
|
+
File.unlink(fn) if File.exist?(fn)
|
112
|
+
EM.start_unix_domain_server fn, TestEchoServer
|
113
|
+
$n = 0
|
114
|
+
$max = 0
|
115
|
+
50.times {
|
116
|
+
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
|
117
|
+
}
|
118
|
+
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
|
119
|
+
}
|
120
|
+
assert_equal(0, $n)
|
121
|
+
assert_equal(50, $max)
|
122
|
+
ensure
|
123
|
+
File.unlink(fn) if File.exist?(fn)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_attach_detach
|
127
|
+
EM.epoll
|
128
|
+
EM.run {
|
129
|
+
EM.add_timer(0.01) { EM.stop }
|
130
|
+
|
131
|
+
r, _ = IO.pipe
|
132
|
+
|
133
|
+
# This tests a regression where detach in the same tick as attach crashes EM
|
134
|
+
EM.watch(r) do |connection|
|
135
|
+
connection.detach
|
136
|
+
end
|
137
|
+
}
|
138
|
+
|
139
|
+
assert true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|