sensu-em 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +12 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +33 -0
- data/GNU +281 -0
- data/Gemfile +2 -0
- data/LICENSE +60 -0
- data/README.md +109 -0
- data/Rakefile +20 -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/eventmachine.gemspec +38 -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 +887 -0
- data/ext/ed.cpp +1988 -0
- data/ext/ed.h +422 -0
- data/ext/em.cpp +2352 -0
- data/ext/em.h +253 -0
- data/ext/eventmachine.h +128 -0
- data/ext/extconf.rb +179 -0
- data/ext/fastfilereader/extconf.rb +103 -0
- data/ext/fastfilereader/mapper.cpp +214 -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 +347 -0
- data/ext/project.h +161 -0
- data/ext/rubymain.cpp +1318 -0
- data/ext/ssl.cpp +468 -0
- data/ext/ssl.h +94 -0
- data/java/.classpath +6 -0
- data/java/.gitignore +1 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
- data/java/src/com/rubyeventmachine/EventCode.java +26 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
- data/java/src/com/rubyeventmachine/SslBox.java +310 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +712 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +231 -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/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -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 +161 -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 +365 -0
- data/lib/em/protocols/smtpserver.rb +643 -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/protocols.rb +37 -0
- data/lib/em/pure_ruby.rb +1017 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +209 -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 +1553 -0
- data/lib/jeventmachine.rb +321 -0
- data/lib/rubyeventmachine.jar +0 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/server.crt +36 -0
- data/tests/server.key +51 -0
- data/tests/test_attach.rb +150 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +53 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +145 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -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 +190 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_idle_connection.rb +25 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_iterator.rb +97 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +102 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +194 -0
- data/tests/test_process_watch.rb +48 -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 +50 -0
- data/tests/test_resolver.rb +55 -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 +37 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -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_echo_data.rb +60 -0
- data/tests/test_ssl_methods.rb +56 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_stomp.rb +37 -0
- data/tests/test_system.rb +42 -0
- data/tests/test_threaded_resource.rb +53 -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 +48 -0
- metadata +297 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'em/completion'
|
2
|
+
|
3
|
+
class TestCompletion < Test::Unit::TestCase
|
4
|
+
def completion
|
5
|
+
@completion ||= EM::Completion.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def crank
|
9
|
+
# This is a slow solution, but this just executes the next tick queue
|
10
|
+
# once. It's the easiest way for now.
|
11
|
+
EM.run { EM.stop }
|
12
|
+
end
|
13
|
+
|
14
|
+
def results
|
15
|
+
@results ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_state
|
19
|
+
assert_equal :unknown, completion.state
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_succeed
|
23
|
+
completion.callback { |val| results << val }
|
24
|
+
completion.succeed :object
|
25
|
+
crank
|
26
|
+
assert_equal :succeeded, completion.state
|
27
|
+
assert_equal [:object], results
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_fail
|
31
|
+
completion.errback { |val| results << val }
|
32
|
+
completion.fail :object
|
33
|
+
crank
|
34
|
+
assert_equal :failed, completion.state
|
35
|
+
assert_equal [:object], results
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_callback
|
39
|
+
completion.callback { results << :callback }
|
40
|
+
completion.errback { results << :errback }
|
41
|
+
completion.succeed
|
42
|
+
crank
|
43
|
+
assert_equal [:callback], results
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_errback
|
47
|
+
completion.callback { results << :callback }
|
48
|
+
completion.errback { results << :errback }
|
49
|
+
completion.fail
|
50
|
+
crank
|
51
|
+
assert_equal [:errback], results
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_stateback
|
55
|
+
completion.stateback(:magic) { results << :stateback }
|
56
|
+
completion.change_state(:magic)
|
57
|
+
crank
|
58
|
+
assert_equal [:stateback], results
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_does_not_enqueue_when_completed
|
62
|
+
completion.callback { results << :callback }
|
63
|
+
completion.succeed
|
64
|
+
completion.errback { results << :errback }
|
65
|
+
completion.fail
|
66
|
+
crank
|
67
|
+
assert_equal [:callback], results
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_completed
|
71
|
+
assert_equal false, completion.completed?
|
72
|
+
completion.succeed
|
73
|
+
assert_equal true, completion.completed?
|
74
|
+
completion.fail
|
75
|
+
assert_equal true, completion.completed?
|
76
|
+
completion.change_state :magic
|
77
|
+
assert_equal false, completion.completed?
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_recursive_callbacks
|
81
|
+
completion.callback do |val|
|
82
|
+
results << val
|
83
|
+
completion.succeed :two
|
84
|
+
end
|
85
|
+
completion.callback do |val|
|
86
|
+
results << val
|
87
|
+
completion.succeed :three
|
88
|
+
end
|
89
|
+
completion.callback do |val|
|
90
|
+
results << val
|
91
|
+
end
|
92
|
+
completion.succeed :one
|
93
|
+
crank
|
94
|
+
assert_equal [:one, :two, :three], results
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_late_defined_callbacks
|
98
|
+
completion.callback { results << :one }
|
99
|
+
completion.succeed
|
100
|
+
crank
|
101
|
+
assert_equal [:one], results
|
102
|
+
completion.callback { results << :two }
|
103
|
+
crank
|
104
|
+
assert_equal [:one, :two], results
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_cleared_completions
|
108
|
+
completion.callback { results << :callback }
|
109
|
+
completion.errback { results << :errback }
|
110
|
+
|
111
|
+
completion.succeed
|
112
|
+
crank
|
113
|
+
completion.fail
|
114
|
+
crank
|
115
|
+
completion.succeed
|
116
|
+
crank
|
117
|
+
|
118
|
+
assert_equal [:callback], results
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_skip_completed_callbacks
|
122
|
+
completion.callback { results << :callback }
|
123
|
+
completion.succeed
|
124
|
+
crank
|
125
|
+
|
126
|
+
completion.errback { results << :errback }
|
127
|
+
completion.fail
|
128
|
+
crank
|
129
|
+
|
130
|
+
assert_equal [:callback], results
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_completions
|
134
|
+
completion.completion { results << :completion }
|
135
|
+
completion.succeed
|
136
|
+
crank
|
137
|
+
assert_equal [:completion], results
|
138
|
+
|
139
|
+
completion.change_state(:unknown)
|
140
|
+
results.clear
|
141
|
+
|
142
|
+
completion.completion { results << :completion }
|
143
|
+
completion.fail
|
144
|
+
crank
|
145
|
+
assert_equal [:completion], results
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_latent_completion
|
149
|
+
completion.completion { results << :completion }
|
150
|
+
completion.succeed
|
151
|
+
crank
|
152
|
+
completion.completion { results << :completion }
|
153
|
+
crank
|
154
|
+
assert_equal [:completion, :completion], results
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_timeout
|
158
|
+
args = [1, 2, 3]
|
159
|
+
EM.run do
|
160
|
+
completion.timeout(0.0001, *args)
|
161
|
+
completion.errback { |*errargs| results << errargs }
|
162
|
+
completion.completion { EM.stop }
|
163
|
+
EM.add_timer(0.1) { flunk 'test timed out' }
|
164
|
+
end
|
165
|
+
assert_equal [[1,2,3]], results
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_timeout_gets_cancelled
|
169
|
+
EM.run do
|
170
|
+
completion.timeout(0.0001, :timeout)
|
171
|
+
completion.errback { results << :errback }
|
172
|
+
completion.succeed
|
173
|
+
EM.add_timer(0.0002) { EM.stop }
|
174
|
+
end
|
175
|
+
assert_equal [], results
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
EM.run {
|
47
|
+
assert_equal(0, EM.num_close_scheduled)
|
48
|
+
EM.connect("127.0.0.1", 9999, DoubleCloseClient) # nothing listening on 9999
|
49
|
+
}
|
50
|
+
assert_equal(1, $num_close_scheduled_1)
|
51
|
+
assert_equal(0, $num_close_scheduled_2)
|
52
|
+
end
|
53
|
+
end
|
data/tests/test_defer.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
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,145 @@
|
|
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
|
+
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
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Run a high-volume version of this test by kicking the number of connections
|
45
|
+
# up past 512. (Each connection uses two sockets, a client and a server.)
|
46
|
+
# (Will require running the test as root)
|
47
|
+
# This test exercises TCP clients and servers.
|
48
|
+
#
|
49
|
+
# XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
|
50
|
+
def _test_descriptors
|
51
|
+
EM.epoll
|
52
|
+
EM.set_descriptor_table_size 60000
|
53
|
+
EM.run {
|
54
|
+
EM.start_server "127.0.0.1", 9800, TestEchoServer
|
55
|
+
$n = 0
|
56
|
+
$max = 0
|
57
|
+
100.times {
|
58
|
+
EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
assert_equal(0, $n)
|
62
|
+
assert_equal(100, $max)
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup
|
66
|
+
@port = next_port
|
67
|
+
end
|
68
|
+
|
69
|
+
module TestDatagramServer
|
70
|
+
def receive_data dgm
|
71
|
+
$in = dgm
|
72
|
+
send_data "abcdefghij"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
module TestDatagramClient
|
76
|
+
def initialize port
|
77
|
+
@port = port
|
78
|
+
end
|
79
|
+
|
80
|
+
def post_init
|
81
|
+
send_datagram "1234567890", "127.0.0.1", @port
|
82
|
+
end
|
83
|
+
|
84
|
+
def receive_data dgm
|
85
|
+
$out = dgm
|
86
|
+
EM.stop
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_datagrams
|
91
|
+
$in = $out = ""
|
92
|
+
EM.run {
|
93
|
+
EM.open_datagram_socket "127.0.0.1", @port, TestDatagramServer
|
94
|
+
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient, @port
|
95
|
+
}
|
96
|
+
assert_equal( "1234567890", $in )
|
97
|
+
assert_equal( "abcdefghij", $out )
|
98
|
+
end
|
99
|
+
|
100
|
+
# XXX this test fails randomly..
|
101
|
+
def _test_unix_domain
|
102
|
+
fn = "/tmp/xxx.chain"
|
103
|
+
EM.epoll
|
104
|
+
EM.set_descriptor_table_size 60000
|
105
|
+
EM.run {
|
106
|
+
# The pure-Ruby version won't let us open the socket if the node already exists.
|
107
|
+
# Not sure, that actually may be correct and the compiled version is wrong.
|
108
|
+
# Pure Ruby also oddly won't let us make that many connections. This test used
|
109
|
+
# to run 100 times. Not sure where that lower connection-limit is coming from in
|
110
|
+
# pure Ruby.
|
111
|
+
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
|
112
|
+
# work on Windows anyway.
|
113
|
+
#
|
114
|
+
File.unlink(fn) if File.exist?(fn)
|
115
|
+
EM.start_unix_domain_server fn, TestEchoServer
|
116
|
+
$n = 0
|
117
|
+
$max = 0
|
118
|
+
50.times {
|
119
|
+
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
|
120
|
+
}
|
121
|
+
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
|
122
|
+
}
|
123
|
+
assert_equal(0, $n)
|
124
|
+
assert_equal(50, $max)
|
125
|
+
ensure
|
126
|
+
File.unlink(fn) if File.exist?(fn)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_attach_detach
|
130
|
+
EM.epoll
|
131
|
+
EM.run {
|
132
|
+
EM.add_timer(0.01) { EM.stop }
|
133
|
+
|
134
|
+
r, w = IO.pipe
|
135
|
+
|
136
|
+
# This tests a regression where detach in the same tick as attach crashes EM
|
137
|
+
EM.watch(r) do |connection|
|
138
|
+
connection.detach
|
139
|
+
end
|
140
|
+
}
|
141
|
+
|
142
|
+
assert true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestErrorHandler < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@exception = Class.new(StandardError)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_error_handler
|
9
|
+
error = nil
|
10
|
+
|
11
|
+
EM.error_handler{ |e|
|
12
|
+
error = e
|
13
|
+
EM.error_handler(nil)
|
14
|
+
EM.stop
|
15
|
+
}
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
EM.run{
|
19
|
+
EM.add_timer(0){
|
20
|
+
raise @exception, 'test'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal error.class, @exception
|
26
|
+
assert_equal error.message, 'test'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_without_error_handler
|
30
|
+
assert_raise @exception do
|
31
|
+
EM.run{
|
32
|
+
EM.add_timer(0){
|
33
|
+
raise @exception, 'test'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/tests/test_exc.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
|
3
|
+
class TestSomeExceptions < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Read the commentary in EM#run.
|
6
|
+
# This test exercises the ensure block in #run that makes sure
|
7
|
+
# EM#release_machine gets called even if an exception is
|
8
|
+
# thrown within the user code. Without the ensured call to release_machine,
|
9
|
+
# the second call to EM#run will fail with a C++ exception
|
10
|
+
# because the machine wasn't cleaned up properly.
|
11
|
+
|
12
|
+
def test_a
|
13
|
+
assert_raises(RuntimeError) {
|
14
|
+
EM.run {
|
15
|
+
raise "some exception"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_b
|
21
|
+
assert_raises(RuntimeError) {
|
22
|
+
EM.run {
|
23
|
+
raise "some exception"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class TestFileWatch < Test::Unit::TestCase
|
5
|
+
if windows?
|
6
|
+
def test_watch_file_raises_unsupported_error
|
7
|
+
assert_raises(EM::Unsupported) do
|
8
|
+
EM.run do
|
9
|
+
file = Tempfile.new("fake_file")
|
10
|
+
EM.watch_file(file.path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
elsif EM.respond_to? :watch_filename
|
15
|
+
module FileWatcher
|
16
|
+
def file_modified
|
17
|
+
$modified = true
|
18
|
+
end
|
19
|
+
def file_deleted
|
20
|
+
$deleted = true
|
21
|
+
end
|
22
|
+
def unbind
|
23
|
+
$unbind = true
|
24
|
+
EM.stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
EM.kqueue = true if EM.kqueue?
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
EM.kqueue = false if EM.kqueue?
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_events
|
37
|
+
EM.run{
|
38
|
+
file = Tempfile.new('em-watch')
|
39
|
+
$tmp_path = file.path
|
40
|
+
|
41
|
+
# watch it
|
42
|
+
watch = EM.watch_file(file.path, FileWatcher)
|
43
|
+
$path = watch.path
|
44
|
+
|
45
|
+
# modify it
|
46
|
+
File.open(file.path, 'w'){ |f| f.puts 'hi' }
|
47
|
+
|
48
|
+
# delete it
|
49
|
+
EM.add_timer(0.01){ file.close; file.delete }
|
50
|
+
}
|
51
|
+
|
52
|
+
assert_equal($path, $tmp_path)
|
53
|
+
assert($modified)
|
54
|
+
assert($deleted)
|
55
|
+
assert($unbind)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
warn "EM.watch_file not implemented, skipping tests in #{__FILE__}"
|
59
|
+
|
60
|
+
# Because some rubies will complain if a TestCase class has no tests
|
61
|
+
def test_em_watch_file_unsupported
|
62
|
+
assert true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|