eventmachine-maglev- 0.12.10 → 1.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.yardopts +7 -0
- data/Gemfile +3 -0
- data/README.md +109 -0
- data/Rakefile +14 -368
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/eventmachine.gemspec +20 -26
- 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/{ex_channel.rb → old/ex_channel.rb} +3 -3
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +40 -29
- data/ext/ed.cpp +189 -134
- data/ext/ed.h +34 -40
- data/ext/em.cpp +388 -340
- data/ext/em.h +29 -32
- data/ext/eventmachine.h +7 -6
- data/ext/extconf.rb +57 -48
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +1 -1
- data/ext/fastfilereader/rubymain.cpp +0 -1
- data/ext/kb.cpp +1 -3
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +158 -112
- data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
- data/lib/em/buftok.rb +35 -63
- data/lib/em/callback.rb +43 -11
- data/lib/em/channel.rb +22 -15
- data/lib/em/completion.rb +303 -0
- data/lib/em/connection.rb +341 -208
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +20 -2
- data/lib/em/file_watch.rb +37 -18
- data/lib/em/iterator.rb +270 -0
- data/lib/em/pool.rb +146 -0
- data/lib/em/process_watch.rb +5 -4
- data/lib/em/processes.rb +8 -4
- data/lib/em/protocols/httpclient.rb +27 -11
- data/lib/em/protocols/httpclient2.rb +15 -5
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/memcache.rb +17 -9
- data/lib/em/protocols/object_protocol.rb +2 -1
- data/lib/em/protocols/postgres3.rb +2 -1
- data/lib/em/protocols/smtpclient.rb +19 -11
- data/lib/em/protocols/smtpserver.rb +101 -8
- data/lib/em/protocols/stomp.rb +9 -7
- data/lib/em/protocols/tcptest.rb +3 -2
- data/lib/em/protocols.rb +1 -1
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
- data/lib/em/queue.rb +23 -13
- data/lib/em/resolver.rb +192 -0
- data/lib/em/spawnable.rb +9 -10
- data/lib/em/streamer.rb +34 -46
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +8 -3
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +582 -686
- data/lib/jeventmachine.rb +25 -3
- data/tasks/package.rake +98 -0
- data/tasks/test.rake +8 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/test_attach.rb +56 -56
- data/tests/test_basic.rb +111 -168
- data/tests/test_channel.rb +5 -6
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +1 -3
- data/tests/test_defer.rb +3 -32
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +27 -57
- 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 +10 -38
- data/tests/test_get_sock_opt.rb +27 -20
- data/tests/test_handler_check.rb +1 -3
- data/tests/test_hc.rb +49 -112
- data/tests/test_httpclient.rb +34 -62
- data/tests/test_httpclient2.rb +14 -39
- data/tests/test_inactivity_timeout.rb +44 -40
- data/tests/test_kb.rb +26 -52
- data/tests/test_ltp.rb +27 -71
- data/tests/test_ltp2.rb +1 -30
- data/tests/test_next_tick.rb +2 -31
- 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_pool.rb +128 -0
- data/tests/test_process_watch.rb +37 -37
- data/tests/test_processes.rb +92 -110
- data/tests/test_proxy_connection.rb +137 -61
- data/tests/test_pure.rb +30 -67
- data/tests/test_queue.rb +10 -4
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +1 -29
- data/tests/test_sasl.rb +8 -33
- data/tests/test_send_file.rb +163 -188
- data/tests/test_servers.rb +12 -55
- data/tests/test_shutdown_hooks.rb +23 -0
- 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_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +52 -91
- data/tests/test_ud.rb +1 -29
- data/tests/test_unbind_reason.rb +31 -0
- metadata +113 -70
- data/README +0 -82
- data/docs/DEFERRABLES +0 -133
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
- data/docs/SMTP +0 -2
- data/docs/SPAWNED_PROCESSES +0 -89
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/lib/evma.rb +0 -32
- data/setup.rb +0 -1585
- data/tests/test_errors.rb +0 -82
- data/tests/testem.rb +0 -31
- data/web/whatis +0 -7
- /data/{docs/GNU → GNU} +0 -0
- /data/{docs/COPYING → LICENSE} +0 -0
- /data/docs/{ChangeLog → old/ChangeLog} +0 -0
- /data/docs/{EPOLL → old/EPOLL} +0 -0
- /data/docs/{INSTALL → old/INSTALL} +0 -0
- /data/docs/{LEGAL → old/LEGAL} +0 -0
- /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
- /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
- /data/docs/{TODO → old/TODO} +0 -0
- /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
- /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_kb.rb
CHANGED
@@ -1,60 +1,34 @@
|
|
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 "../lib"
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
30
2
|
|
31
3
|
class TestKeyboardEvents < Test::Unit::TestCase
|
32
4
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
5
|
+
if !jruby?
|
6
|
+
module KbHandler
|
7
|
+
include EM::Protocols::LineText2
|
8
|
+
def receive_line d
|
9
|
+
EM::stop if d == "STOP"
|
10
|
+
end
|
11
|
+
end
|
38
12
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
13
|
+
# This test doesn't actually do anything useful but is here to
|
14
|
+
# illustrate the usage. If you removed the timer and ran this test
|
15
|
+
# by itself on a console, and then typed into the console, it would
|
16
|
+
# work.
|
17
|
+
# I don't know how to get the test harness to simulate actual keystrokes.
|
18
|
+
# When someone figures that out, then we can make this a real test.
|
19
|
+
#
|
20
|
+
def test_kb
|
21
|
+
EM.run {
|
22
|
+
EM.open_keyboard KbHandler
|
23
|
+
EM::Timer.new(1) { EM.stop }
|
24
|
+
} if $stdout.tty? # don't run the test unless it stands a chance of validity.
|
43
25
|
end
|
44
|
-
|
26
|
+
else
|
27
|
+
warn "EM.open_keyboard not implemented, skipping tests in #{__FILE__}"
|
45
28
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# I don't know how to get the test harness to simulate actual keystrokes.
|
51
|
-
# When someone figures that out, then we can make this a real test.
|
52
|
-
#
|
53
|
-
def test_kb
|
54
|
-
EM.run {
|
55
|
-
EM.open_keyboard KbHandler
|
56
|
-
EM::Timer.new(1) { EM.stop }
|
57
|
-
} if $stdout.tty? # don't run the test unless it stands a chance of validity.
|
29
|
+
# Because some rubies will complain if a TestCase class has no tests
|
30
|
+
def test_em_open_keyboard_unsupported
|
31
|
+
assert true
|
32
|
+
end
|
58
33
|
end
|
59
|
-
|
60
34
|
end
|
data/tests/test_ltp.rb
CHANGED
@@ -1,42 +1,8 @@
|
|
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
|
-
|
28
|
-
require 'eventmachine'
|
29
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
30
2
|
|
31
3
|
class TestLineAndTextProtocol < Test::Unit::TestCase
|
32
4
|
|
33
|
-
|
34
|
-
TestPort = 8905
|
35
|
-
|
36
|
-
|
37
|
-
#--------------------------------------------------------------------
|
38
|
-
|
39
|
-
class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
|
5
|
+
class SimpleLineTest < EM::P::LineAndTextProtocol
|
40
6
|
def receive_line line
|
41
7
|
@line_buffer << line
|
42
8
|
end
|
@@ -46,26 +12,29 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
46
12
|
def set_receive_data(&blk)
|
47
13
|
@rdb = blk
|
48
14
|
end
|
49
|
-
|
15
|
+
|
50
16
|
def receive_data data
|
51
17
|
@rdb.call(data) if @rdb
|
52
18
|
end
|
53
|
-
|
19
|
+
|
54
20
|
def unbind
|
55
21
|
EM.add_timer(0.1) { EM.stop }
|
56
22
|
end
|
57
23
|
end
|
58
24
|
|
25
|
+
def setup
|
26
|
+
@port = next_port
|
27
|
+
end
|
59
28
|
|
60
29
|
def test_simple_lines
|
61
30
|
lines_received = []
|
62
|
-
|
63
|
-
|
31
|
+
EM.run {
|
32
|
+
EM.start_server( "127.0.0.1", @port, SimpleLineTest ) do |conn|
|
64
33
|
conn.instance_eval "@line_buffer = lines_received"
|
65
34
|
end
|
66
|
-
|
35
|
+
setup_timeout
|
67
36
|
|
68
|
-
|
37
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
69
38
|
c.send_data "aaa\nbbb\r\nccc\n"
|
70
39
|
c.close_connection_after_writing
|
71
40
|
end
|
@@ -75,7 +44,7 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
75
44
|
|
76
45
|
#--------------------------------------------------------------------
|
77
46
|
|
78
|
-
class SimpleLineTest <
|
47
|
+
class SimpleLineTest < EM::P::LineAndTextProtocol
|
79
48
|
def receive_error text
|
80
49
|
@error_message << text
|
81
50
|
end
|
@@ -83,13 +52,13 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
83
52
|
|
84
53
|
def test_overlength_lines
|
85
54
|
lines_received = []
|
86
|
-
|
87
|
-
|
55
|
+
EM.run {
|
56
|
+
EM.start_server( "127.0.0.1", @port, SimpleLineTest ) do |conn|
|
88
57
|
conn.instance_eval "@error_message = lines_received"
|
89
58
|
end
|
90
|
-
|
59
|
+
setup_timeout
|
91
60
|
|
92
|
-
|
61
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
93
62
|
c.send_data "a" * (16*1024 + 1)
|
94
63
|
c.send_data "\n"
|
95
64
|
c.close_connection_after_writing
|
@@ -102,9 +71,7 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
102
71
|
|
103
72
|
#--------------------------------------------------------------------
|
104
73
|
|
105
|
-
class LineAndTextTest <
|
106
|
-
def post_init
|
107
|
-
end
|
74
|
+
class LineAndTextTest < EM::P::LineAndTextProtocol
|
108
75
|
def receive_line line
|
109
76
|
if line =~ /content-length:\s*(\d+)/i
|
110
77
|
@content_length = $1.to_i
|
@@ -120,15 +87,11 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
120
87
|
|
121
88
|
def test_lines_and_text
|
122
89
|
output = ''
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
|
127
|
-
conn.instance_eval "@lines = lines_received; @text = text_received"
|
128
|
-
end
|
129
|
-
EventMachine.add_timer(4) {assert(false, "test timed out")}
|
90
|
+
EM.run {
|
91
|
+
EM.start_server( "127.0.0.1", @port, LineAndTextTest )
|
92
|
+
setup_timeout
|
130
93
|
|
131
|
-
|
94
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
132
95
|
c.set_receive_data { |data| output << data }
|
133
96
|
c.send_data "Content-length: 400\n"
|
134
97
|
c.send_data "\n"
|
@@ -142,9 +105,7 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
142
105
|
#--------------------------------------------------------------------
|
143
106
|
|
144
107
|
|
145
|
-
class BinaryTextTest <
|
146
|
-
def post_init
|
147
|
-
end
|
108
|
+
class BinaryTextTest < EM::P::LineAndTextProtocol
|
148
109
|
def receive_line line
|
149
110
|
if line =~ /content-length:\s*(\d+)/i
|
150
111
|
set_binary_mode $1.to_i
|
@@ -160,23 +121,18 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
|
|
160
121
|
|
161
122
|
def test_binary_text
|
162
123
|
output = ''
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
|
167
|
-
conn.instance_eval "@lines = lines_received; @text = text_received"
|
168
|
-
end
|
169
|
-
EventMachine.add_timer(4) {assert(false, "test timed out")}
|
124
|
+
EM.run {
|
125
|
+
EM.start_server( "127.0.0.1", @port, BinaryTextTest )
|
126
|
+
setup_timeout
|
170
127
|
|
171
|
-
|
128
|
+
EM.connect "127.0.0.1", @port, StopClient do |c|
|
172
129
|
c.set_receive_data { |data| output << data }
|
173
130
|
c.send_data "Content-length: 10000\n"
|
174
131
|
c.send_data "A" * 10000
|
175
|
-
EM.add_timer(0.
|
132
|
+
EM.add_timer(0.1) { c.close_connection_after_writing }
|
176
133
|
end
|
177
134
|
}
|
178
135
|
assert_equal( "received 10000 bytes", output )
|
179
136
|
end
|
180
137
|
|
181
|
-
#--------------------------------------------------------------------
|
182
138
|
end
|
data/tests/test_ltp2.rb
CHANGED
@@ -1,33 +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
|
-
#
|
27
|
-
|
28
|
-
$:.unshift "../lib"
|
29
|
-
require 'eventmachine'
|
30
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
31
2
|
|
32
3
|
# TODO!!! Need tests for overlength headers and text bodies.
|
33
4
|
|
data/tests/test_next_tick.rb
CHANGED
@@ -1,33 +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
|
-
#
|
27
|
-
|
28
|
-
$:.unshift "../lib"
|
29
|
-
require 'eventmachine'
|
30
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
31
2
|
|
32
3
|
class TestNextTick < Test::Unit::TestCase
|
33
4
|
|
@@ -61,7 +32,7 @@ class TestNextTick < Test::Unit::TestCase
|
|
61
32
|
def test_pre_run_queue
|
62
33
|
x = false
|
63
34
|
EM.next_tick { EM.stop; x = true }
|
64
|
-
EM.run { EM.add_timer(0.
|
35
|
+
EM.run { EM.add_timer(0.01) { EM.stop } }
|
65
36
|
assert x
|
66
37
|
end
|
67
38
|
|
@@ -1,11 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestObjectProtocol < Test::Unit::TestCase
|
6
|
-
Host = "127.0.0.1"
|
7
|
-
Port = 9550
|
8
|
-
|
9
4
|
module Server
|
10
5
|
include EM::P::ObjectProtocol
|
11
6
|
def post_init
|
@@ -25,13 +20,17 @@ class TestObjectProtocol < Test::Unit::TestCase
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
23
|
+
def setup
|
24
|
+
@port = next_port
|
25
|
+
end
|
26
|
+
|
28
27
|
def test_send_receive
|
29
28
|
EM.run{
|
30
|
-
EM.start_server
|
31
|
-
EM.connect
|
29
|
+
EM.start_server "127.0.0.1", @port, Server
|
30
|
+
EM.connect "127.0.0.1", @port, Client
|
32
31
|
}
|
33
32
|
|
34
33
|
assert($client == {:hello=>'world'})
|
35
34
|
assert($server == {'you_said'=>{:hello=>'world'}})
|
36
35
|
end
|
37
|
-
end
|
36
|
+
end
|
data/tests/test_pause.rb
CHANGED
@@ -1,30 +1,21 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'socket'
|
4
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
5
2
|
|
6
3
|
class TestPause < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
assert(!EM.reactor_running?)
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
assert(!EM.reactor_running?)
|
16
|
-
end
|
4
|
+
if EM.respond_to? :pause_connection
|
5
|
+
def setup
|
6
|
+
@port = next_port
|
7
|
+
end
|
17
8
|
|
18
|
-
|
9
|
+
def teardown
|
10
|
+
assert(!EM.reactor_running?)
|
11
|
+
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
server = nil
|
13
|
+
def test_pause_resume
|
14
|
+
server = nil
|
23
15
|
|
24
|
-
|
16
|
+
s_rx = c_rx = 0
|
25
17
|
|
26
|
-
|
27
|
-
EM.start_server TestHost, TestPort, Module.new {
|
18
|
+
test_server = Module.new do
|
28
19
|
define_method :post_init do
|
29
20
|
server = self
|
30
21
|
end
|
@@ -39,32 +30,49 @@ class TestPause < Test::Unit::TestCase
|
|
39
30
|
# be sent and no more incoming data will be received
|
40
31
|
pause
|
41
32
|
end
|
42
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
test_client = Module.new do
|
36
|
+
def post_init
|
37
|
+
EM.add_periodic_timer(0.01) do
|
38
|
+
send_data 'hello'
|
39
|
+
end
|
40
|
+
end
|
43
41
|
|
44
|
-
c = EM.connect TestHost, TestPort, Module.new {
|
45
42
|
define_method :receive_data do |data|
|
46
43
|
c_rx += 1
|
47
44
|
end
|
48
|
-
|
49
|
-
EM.add_periodic_timer(0.01) { c.send_data 'hi' }
|
45
|
+
end
|
50
46
|
|
51
|
-
EM.
|
52
|
-
|
53
|
-
|
54
|
-
test.assert server.paused?
|
47
|
+
EM.run do
|
48
|
+
EM.start_server "127.0.0.1", @port, test_server
|
49
|
+
EM.connect "127.0.0.1", @port, test_client
|
55
50
|
|
56
|
-
|
57
|
-
|
51
|
+
EM.add_timer(0.05) do
|
52
|
+
assert_equal 1, s_rx
|
53
|
+
assert_equal 0, c_rx
|
54
|
+
assert server.paused?
|
58
55
|
|
59
|
-
|
56
|
+
# resume server, queued outgoing and incoming data will be flushed
|
57
|
+
server.resume
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
assert !server.paused?
|
60
|
+
|
61
|
+
EM.add_timer(0.05) do
|
62
|
+
assert server.paused?
|
63
|
+
assert s_rx > 1
|
64
|
+
assert c_rx > 0
|
65
|
+
EM.stop
|
66
|
+
end
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
70
|
+
else
|
71
|
+
warn "EM.pause_connection not implemented, skipping tests in #{__FILE__}"
|
72
|
+
|
73
|
+
# Because some rubies will complain if a TestCase class has no tests
|
74
|
+
def test_em_pause_connection_not_implemented
|
75
|
+
assert true
|
76
|
+
end
|
69
77
|
end
|
70
78
|
end
|
@@ -1,48 +1,52 @@
|
|
1
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestPendingConnectTimeout < Test::Unit::TestCase
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
assert_equal(20.0, $timeout)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_set_and_get
|
19
|
-
$timeout = nil
|
20
|
-
EM.run {
|
21
|
-
c = EM.connect("1.2.3.4", 54321)
|
22
|
-
c.pending_connect_timeout = 2.5
|
23
|
-
$timeout = c.pending_connect_timeout
|
24
|
-
EM.stop
|
25
|
-
}
|
26
|
-
|
27
|
-
assert_equal(2.5, $timeout)
|
28
|
-
end
|
5
|
+
if EM.respond_to? :get_pending_connect_timeout
|
6
|
+
def test_default
|
7
|
+
EM.run {
|
8
|
+
c = EM.connect("127.0.0.1", 54321)
|
9
|
+
assert_equal 20.0, c.pending_connect_timeout
|
10
|
+
EM.stop
|
11
|
+
}
|
12
|
+
end
|
29
13
|
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
def test_set_and_get
|
15
|
+
EM.run {
|
16
|
+
c = EM.connect("127.0.0.1", 54321)
|
17
|
+
c.pending_connect_timeout = 2.5
|
18
|
+
assert_equal 2.5, c.pending_connect_timeout
|
19
|
+
EM.stop
|
20
|
+
}
|
33
21
|
end
|
34
|
-
end
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
23
|
+
def test_for_real
|
24
|
+
start, finish = nil
|
25
|
+
|
26
|
+
timeout_handler = Module.new do
|
27
|
+
define_method :unbind do
|
28
|
+
finish = Time.now
|
29
|
+
EM.stop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
EM.run {
|
34
|
+
setup_timeout
|
35
|
+
EM.heartbeat_interval = 0.1
|
36
|
+
start = Time.now
|
37
|
+
c = EM.connect("1.2.3.4", 54321, timeout_handler)
|
38
|
+
c.pending_connect_timeout = 0.2
|
39
|
+
}
|
40
|
+
|
41
|
+
assert_in_delta(0.2, (finish - start), 0.1)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
warn "EM.pending_connect_timeout not implemented, skipping tests in #{__FILE__}"
|
44
45
|
|
45
|
-
|
46
|
+
# Because some rubies will complain if a TestCase class has no tests
|
47
|
+
def test_em_pending_connect_timeout_not_implemented
|
48
|
+
assert true
|
49
|
+
end
|
46
50
|
end
|
47
51
|
|
48
52
|
end
|