sensu-em 2.4.0-x86-mingw32
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 +37 -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 +1992 -0
- data/ext/ed.h +424 -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 +476 -0
- data/ext/ssl.h +95 -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 +531 -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 +179 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
- data/java/src/com/rubyeventmachine/SslBox.java +311 -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 +716 -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 +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.rb +37 -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/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/fastfilereaderext.rb +2 -0
- data/lib/jeventmachine.rb +321 -0
- data/lib/rubyeventmachine.rb +2 -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 +300 -0
data/rakelib/test.rake
ADDED
data/tests/client.crt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIFRDCCAywCAQEwDQYJKoZIhvcNAQEFBQAwaDELMAkGA1UEBhMCRU0xFTATBgNV
|
3
|
+
BAgTDEV2ZW50TWFjaGluZTEVMBMGA1UEChMM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pe8d8mIQngRjD+nuLI/uFUglPzabDOCOln2aycjg1mA6ecXP1XMEVbu
|
48
|
+
0RB/0IE36XTMfZ+u9+TRjkBLpmUaX1FdIQQWfwUou/LfaXotoQlhSGAcprLrncuJ
|
49
|
+
T44UATYEgO/q9pMM33bdE3eBYZHoT9mSvqoLCN4s0LuwOYItIxLKUj0GulL0VQOI
|
50
|
+
SZi+0A1c8cVDXgApkBrWPDQIR9JS4de0gW4hnDoUvHtUc2TYPRnz6N9MtFY=
|
51
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
class EMTestTimeout < StandardError ; end
|
8
|
+
|
9
|
+
def setup_timeout(timeout = TIMEOUT_INTERVAL)
|
10
|
+
EM.schedule {
|
11
|
+
EM.add_timer(timeout) {
|
12
|
+
raise EMTestTimeout, "Test was cancelled after #{timeout} seconds."
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def port_in_use?(port, host="127.0.0.1")
|
18
|
+
s = TCPSocket.new(host, port)
|
19
|
+
s.close
|
20
|
+
s
|
21
|
+
rescue Errno::ECONNREFUSED
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def next_port
|
26
|
+
@@port ||= 9000
|
27
|
+
begin
|
28
|
+
@@port += 1
|
29
|
+
end while port_in_use?(@@port)
|
30
|
+
|
31
|
+
@@port
|
32
|
+
end
|
33
|
+
|
34
|
+
def exception_class
|
35
|
+
jruby? ? NativeException : RuntimeError
|
36
|
+
end
|
37
|
+
|
38
|
+
module PlatformHelper
|
39
|
+
# http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
|
40
|
+
def windows?
|
41
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
42
|
+
end
|
43
|
+
|
44
|
+
# http://stackoverflow.com/questions/1342535/how-can-i-tell-if-im-running-from-jruby-vs-ruby/1685970#1685970
|
45
|
+
def jruby?
|
46
|
+
defined? JRUBY_VERSION
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
include PlatformHelper
|
51
|
+
extend PlatformHelper
|
52
|
+
|
53
|
+
# Tests run significantly slower on windows. YMMV
|
54
|
+
TIMEOUT_INTERVAL = windows? ? 1 : 0.25
|
55
|
+
|
56
|
+
def silent
|
57
|
+
backup, $VERBOSE = $VERBOSE, nil
|
58
|
+
begin
|
59
|
+
yield
|
60
|
+
ensure
|
61
|
+
$VERBOSE = backup
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/tests/server.crt
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIGVzCCBD+gAwIBAgIJAJjaQGZpm55mMA0GCSqGSIb3DQEBBQUAMHoxCzAJBgNV
|
3
|
+
BAYTAkVNMRUwEwYDVQQIEwxFdmVudE1hY2hpbmUxFTATBgNVBAoTDEV2ZW50TWFj
|
4
|
+
aGluZTEdMBsGA1UECxMURGV2ZWxvcG1lbnQgKFNlcnZlcikxHjAcBgNVBAMTFUV2
|
5
|
+
ZW50TWFjaGluZSAoU2VydmVyKTAeFw0xMzEwMDMyMDQ1NDBaFw0xNDEwMDMyMDQ1
|
6
|
+
NDBaMHoxCzAJBgNVBAYTAkVNMRUwEwYDVQQIEwxFdmVudE1hY2hpbmUxFTATBgNV
|
7
|
+
BAoTDEV2ZW50TWFjaGluZTEdMBsGA1UECxMURGV2ZWxvcG1lbnQgKFNlcnZlcikx
|
8
|
+
HjAcBgNVBAMTFUV2ZW50TWFjaGluZSAoU2VydmVyKTCCAiIwDQYJKoZIhvcNAQEB
|
9
|
+
BQADggIPADCCAgoCggIBANnSWRM69c59PjmeXgGviFxcWZh6bmR99Rkr7qHWFO6x
|
10
|
+
sXdtXRpbcbA0AGF1qfVaXSnbg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qorkTp8Ixtmbf3/LlNZqBkJ7wuBWmEk8WFVPueSK0hER0sHE74j1+
|
49
|
+
CM2rAbL1YLoz3YVlVfKyxhwXWL1vP/LfQSBPTxrPpktjbSKNJAPh+JPdZvu67o43
|
50
|
+
Ot9/TM6o8Y0zS5j7iXblrEef12Fga0fEwgob6xC/Nh+Twd+aSFp5ILUACfow
|
51
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
class TestAttach < Test::Unit::TestCase
|
5
|
+
class EchoServer < EM::Connection
|
6
|
+
def receive_data data
|
7
|
+
$received_data << data
|
8
|
+
send_data data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class EchoClient < EM::Connection
|
13
|
+
def initialize socket
|
14
|
+
self.notify_readable = true
|
15
|
+
@socket = socket
|
16
|
+
@socket.write("abc\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
def notify_readable
|
20
|
+
$read = @socket.readline
|
21
|
+
$fd = detach
|
22
|
+
end
|
23
|
+
|
24
|
+
def unbind
|
25
|
+
EM.next_tick do
|
26
|
+
@socket.write("def\n")
|
27
|
+
EM.add_timer(0.1) { EM.stop }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
@port = next_port
|
34
|
+
$read, $r, $w, $fd = nil
|
35
|
+
$received_data = ""
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
[$r, $w].each do |io|
|
40
|
+
io.close rescue nil
|
41
|
+
end
|
42
|
+
$received_data = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_attach
|
46
|
+
socket = nil
|
47
|
+
|
48
|
+
EM.run {
|
49
|
+
EM.start_server "127.0.0.1", @port, EchoServer
|
50
|
+
socket = TCPSocket.new "127.0.0.1", @port
|
51
|
+
EM.watch socket, EchoClient, socket
|
52
|
+
}
|
53
|
+
|
54
|
+
assert_equal $read, "abc\n"
|
55
|
+
unless jruby? # jruby filenos are not real
|
56
|
+
assert_equal $fd, socket.fileno
|
57
|
+
end
|
58
|
+
assert_equal false, socket.closed?
|
59
|
+
assert_equal socket.readline, "def\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
module PipeWatch
|
63
|
+
def notify_readable
|
64
|
+
$read = $r.readline
|
65
|
+
EM.stop
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_attach_server
|
70
|
+
$before = TCPServer.new("127.0.0.1", @port)
|
71
|
+
sig = nil
|
72
|
+
EM.run {
|
73
|
+
sig = EM.attach_server $before, EchoServer
|
74
|
+
|
75
|
+
handler = Class.new(EM::Connection) do
|
76
|
+
def initialize
|
77
|
+
send_data "hello world"
|
78
|
+
close_connection_after_writing
|
79
|
+
EM.add_timer(0.1) { EM.stop }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
EM.connect("127.0.0.1", @port, handler)
|
83
|
+
}
|
84
|
+
|
85
|
+
assert_equal false, $before.closed?
|
86
|
+
assert_equal "hello world", $received_data
|
87
|
+
assert sig.is_a?(Integer)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_attach_pipe
|
91
|
+
EM.run{
|
92
|
+
$r, $w = IO.pipe
|
93
|
+
EM.watch $r, PipeWatch do |c|
|
94
|
+
c.notify_readable = true
|
95
|
+
end
|
96
|
+
$w.write("ghi\n")
|
97
|
+
}
|
98
|
+
|
99
|
+
assert_equal $read, "ghi\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_set_readable
|
103
|
+
before, after = nil
|
104
|
+
|
105
|
+
EM.run{
|
106
|
+
$r, $w = IO.pipe
|
107
|
+
c = EM.watch $r, PipeWatch do |con|
|
108
|
+
con.notify_readable = false
|
109
|
+
end
|
110
|
+
|
111
|
+
EM.next_tick{
|
112
|
+
before = c.notify_readable?
|
113
|
+
c.notify_readable = true
|
114
|
+
after = c.notify_readable?
|
115
|
+
}
|
116
|
+
|
117
|
+
$w.write("jkl\n")
|
118
|
+
}
|
119
|
+
|
120
|
+
assert !before
|
121
|
+
assert after
|
122
|
+
assert_equal $read, "jkl\n"
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_read_write_pipe
|
126
|
+
result = nil
|
127
|
+
|
128
|
+
pipe_reader = Module.new do
|
129
|
+
define_method :receive_data do |data|
|
130
|
+
result = data
|
131
|
+
EM.stop
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
r,w = IO.pipe
|
136
|
+
|
137
|
+
EM.run {
|
138
|
+
EM.attach r, pipe_reader
|
139
|
+
writer = EM.attach(w)
|
140
|
+
writer.send_data 'ghi'
|
141
|
+
|
142
|
+
# XXX: Process will hang in Windows without this line
|
143
|
+
writer.close_connection_after_writing
|
144
|
+
}
|
145
|
+
|
146
|
+
assert_equal "ghi", result
|
147
|
+
ensure
|
148
|
+
[r,w].each {|io| io.close rescue nil }
|
149
|
+
end
|
150
|
+
end
|
data/tests/test_basic.rb
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
require 'em_test_helper'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
class TestBasic < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@port = next_port
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_connection_class_cache
|
10
|
+
mod = Module.new
|
11
|
+
a, b = nil, nil
|
12
|
+
EM.run {
|
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
|
16
|
+
EM.stop
|
17
|
+
}
|
18
|
+
assert_equal a.class, b.class
|
19
|
+
assert_kind_of EM::Connection, a
|
20
|
+
end
|
21
|
+
|
22
|
+
#-------------------------------------
|
23
|
+
|
24
|
+
|
25
|
+
def test_em
|
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
|
34
|
+
end
|
35
|
+
|
36
|
+
#-------------------------------------
|
37
|
+
|
38
|
+
def test_timer
|
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
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#-------------------------------------
|
52
|
+
|
53
|
+
# This test once threw an already-running exception.
|
54
|
+
module Trivial
|
55
|
+
def post_init
|
56
|
+
EM.stop
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_server
|
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
|
68
|
+
end
|
69
|
+
|
70
|
+
#--------------------------------------
|
71
|
+
|
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
|
74
|
+
# even after the supplied block completes.
|
75
|
+
def test_run_block
|
76
|
+
assert !EM.reactor_running?
|
77
|
+
a = nil
|
78
|
+
EM.run_block { a = "Worked" }
|
79
|
+
assert a
|
80
|
+
assert !EM.reactor_running?
|
81
|
+
end
|
82
|
+
|
83
|
+
class UnbindError < EM::Connection
|
84
|
+
ERR = Class.new(StandardError)
|
85
|
+
def initialize *args
|
86
|
+
super
|
87
|
+
end
|
88
|
+
def connection_completed
|
89
|
+
close_connection_after_writing
|
90
|
+
end
|
91
|
+
def unbind
|
92
|
+
raise ERR
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_unbind_error
|
97
|
+
assert_raises( UnbindError::ERR ) {
|
98
|
+
EM.run {
|
99
|
+
EM.start_server "127.0.0.1", @port
|
100
|
+
EM.connect "127.0.0.1", @port, UnbindError
|
101
|
+
}
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
module BrsTestSrv
|
106
|
+
def receive_data data
|
107
|
+
$received << data
|
108
|
+
end
|
109
|
+
def unbind
|
110
|
+
EM.stop
|
111
|
+
end
|
112
|
+
end
|
113
|
+
module BrsTestCli
|
114
|
+
def post_init
|
115
|
+
send_data $sent
|
116
|
+
close_connection_after_writing
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# From ticket #50
|
121
|
+
def test_byte_range_send
|
122
|
+
$received = ''
|
123
|
+
$sent = (0..255).to_a.pack('C*')
|
124
|
+
EM::run {
|
125
|
+
EM::start_server "127.0.0.1", @port, BrsTestSrv
|
126
|
+
EM::connect "127.0.0.1", @port, BrsTestCli
|
127
|
+
|
128
|
+
setup_timeout
|
129
|
+
}
|
130
|
+
assert_equal($sent, $received)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_bind_connect
|
134
|
+
local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
|
135
|
+
|
136
|
+
bind_port = next_port
|
137
|
+
|
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
|
145
|
+
end
|
146
|
+
end
|
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
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_reactor_thread?
|
160
|
+
assert !EM.reactor_thread?
|
161
|
+
EM.run { assert EM.reactor_thread?; EM.stop }
|
162
|
+
assert !EM.reactor_thread?
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_schedule_on_reactor_thread
|
166
|
+
x = false
|
167
|
+
EM.run do
|
168
|
+
EM.schedule { x = true }
|
169
|
+
EM.stop
|
170
|
+
end
|
171
|
+
assert x
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_schedule_from_thread
|
175
|
+
x = false
|
176
|
+
EM.run do
|
177
|
+
Thread.new { EM.schedule { x = true; EM.stop } }.join
|
178
|
+
end
|
179
|
+
assert x
|
180
|
+
end
|
181
|
+
|
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__}"
|
194
|
+
end
|
195
|
+
|
196
|
+
module PostInitRaiser
|
197
|
+
ERR = Class.new(StandardError)
|
198
|
+
def post_init
|
199
|
+
raise ERR
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_bubble_errors_from_post_init
|
204
|
+
assert_raises(PostInitRaiser::ERR) do
|
205
|
+
EM.run do
|
206
|
+
EM.start_server "127.0.0.1", @port
|
207
|
+
EM.connect "127.0.0.1", @port, PostInitRaiser
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
module InitializeRaiser
|
213
|
+
ERR = Class.new(StandardError)
|
214
|
+
def initialize
|
215
|
+
raise ERR
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_bubble_errors_from_initialize
|
220
|
+
assert_raises(InitializeRaiser::ERR) do
|
221
|
+
EM.run do
|
222
|
+
EM.start_server "127.0.0.1", @port
|
223
|
+
EM.connect "127.0.0.1", @port, InitializeRaiser
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_schedule_close
|
229
|
+
localhost, port = '127.0.0.1', 9000
|
230
|
+
timer_ran = false
|
231
|
+
num_close_scheduled = nil
|
232
|
+
EM.run do
|
233
|
+
assert_equal 0, EM.num_close_scheduled
|
234
|
+
EM.add_timer(1) { timer_ran = true; EM.stop }
|
235
|
+
EM.start_server localhost, port do |s|
|
236
|
+
s.close_connection
|
237
|
+
num_close_scheduled = EM.num_close_scheduled
|
238
|
+
end
|
239
|
+
EM.connect localhost, port do |c|
|
240
|
+
def c.unbind
|
241
|
+
EM.stop
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
assert !timer_ran
|
246
|
+
assert_equal 1, num_close_scheduled
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_fork_safe
|
250
|
+
return unless cpid = fork { exit! } rescue false
|
251
|
+
|
252
|
+
read, write = IO.pipe
|
253
|
+
EM.run do
|
254
|
+
cpid = fork do
|
255
|
+
write.puts "forked"
|
256
|
+
EM.run do
|
257
|
+
EM.next_tick do
|
258
|
+
write.puts "EM ran"
|
259
|
+
exit!
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
EM.stop
|
264
|
+
end
|
265
|
+
Process.waitall
|
266
|
+
assert_equal "forked\n", read.readline
|
267
|
+
assert_equal "EM ran\n", read.readline
|
268
|
+
ensure
|
269
|
+
read.close rescue nil
|
270
|
+
write.close rescue nil
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_error_handler_idempotent # issue 185
|
274
|
+
errors = []
|
275
|
+
ticks = []
|
276
|
+
EM.error_handler do |e|
|
277
|
+
errors << e
|
278
|
+
end
|
279
|
+
|
280
|
+
EM.run do
|
281
|
+
EM.next_tick do
|
282
|
+
ticks << :first
|
283
|
+
raise
|
284
|
+
end
|
285
|
+
EM.next_tick do
|
286
|
+
ticks << :second
|
287
|
+
end
|
288
|
+
EM.add_timer(0.001) { EM.stop }
|
289
|
+
end
|
290
|
+
|
291
|
+
assert_equal 1, errors.size
|
292
|
+
assert_equal [:first, :second], ticks
|
293
|
+
end
|
294
|
+
end
|