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.
Files changed (174) hide show
  1. data/.gitignore +7 -0
  2. data/.yardopts +7 -0
  3. data/Gemfile +3 -0
  4. data/README.md +109 -0
  5. data/Rakefile +14 -368
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/DEFERRABLES +246 -0
  9. data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
  10. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  11. data/docs/old/SMTP +4 -0
  12. data/docs/old/SPAWNED_PROCESSES +148 -0
  13. data/eventmachine.gemspec +20 -26
  14. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  15. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  16. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  17. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  18. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  19. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  20. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  21. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  22. data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
  23. data/examples/old/ex_tick_loop_array.rb +15 -0
  24. data/examples/old/ex_tick_loop_counter.rb +32 -0
  25. data/ext/binder.cpp +0 -1
  26. data/ext/cmain.cpp +40 -29
  27. data/ext/ed.cpp +189 -134
  28. data/ext/ed.h +34 -40
  29. data/ext/em.cpp +388 -340
  30. data/ext/em.h +29 -32
  31. data/ext/eventmachine.h +7 -6
  32. data/ext/extconf.rb +57 -48
  33. data/ext/fastfilereader/extconf.rb +5 -3
  34. data/ext/fastfilereader/mapper.cpp +1 -1
  35. data/ext/fastfilereader/rubymain.cpp +0 -1
  36. data/ext/kb.cpp +1 -3
  37. data/ext/pipe.cpp +9 -11
  38. data/ext/project.h +12 -8
  39. data/ext/rubymain.cpp +158 -112
  40. data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
  41. data/lib/em/buftok.rb +35 -63
  42. data/lib/em/callback.rb +43 -11
  43. data/lib/em/channel.rb +22 -15
  44. data/lib/em/completion.rb +303 -0
  45. data/lib/em/connection.rb +341 -208
  46. data/lib/em/deferrable/pool.rb +2 -0
  47. data/lib/em/deferrable.rb +20 -2
  48. data/lib/em/file_watch.rb +37 -18
  49. data/lib/em/iterator.rb +270 -0
  50. data/lib/em/pool.rb +146 -0
  51. data/lib/em/process_watch.rb +5 -4
  52. data/lib/em/processes.rb +8 -4
  53. data/lib/em/protocols/httpclient.rb +27 -11
  54. data/lib/em/protocols/httpclient2.rb +15 -5
  55. data/lib/em/protocols/line_protocol.rb +29 -0
  56. data/lib/em/protocols/memcache.rb +17 -9
  57. data/lib/em/protocols/object_protocol.rb +2 -1
  58. data/lib/em/protocols/postgres3.rb +2 -1
  59. data/lib/em/protocols/smtpclient.rb +19 -11
  60. data/lib/em/protocols/smtpserver.rb +101 -8
  61. data/lib/em/protocols/stomp.rb +9 -7
  62. data/lib/em/protocols/tcptest.rb +3 -2
  63. data/lib/em/protocols.rb +1 -1
  64. data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
  65. data/lib/em/queue.rb +23 -13
  66. data/lib/em/resolver.rb +192 -0
  67. data/lib/em/spawnable.rb +9 -10
  68. data/lib/em/streamer.rb +34 -46
  69. data/lib/em/threaded_resource.rb +90 -0
  70. data/lib/em/tick_loop.rb +85 -0
  71. data/lib/em/timers.rb +8 -3
  72. data/lib/em/version.rb +1 -1
  73. data/lib/eventmachine.rb +582 -686
  74. data/lib/jeventmachine.rb +25 -3
  75. data/tasks/package.rake +98 -0
  76. data/tasks/test.rake +8 -0
  77. data/tests/em_test_helper.rb +64 -0
  78. data/tests/test_attach.rb +56 -56
  79. data/tests/test_basic.rb +111 -168
  80. data/tests/test_channel.rb +5 -6
  81. data/tests/test_completion.rb +177 -0
  82. data/tests/test_connection_count.rb +1 -3
  83. data/tests/test_defer.rb +3 -32
  84. data/tests/test_deferrable.rb +35 -0
  85. data/tests/test_epoll.rb +27 -57
  86. data/tests/test_error_handler.rb +10 -7
  87. data/tests/test_exc.rb +6 -33
  88. data/tests/test_file_watch.rb +51 -35
  89. data/tests/test_futures.rb +10 -38
  90. data/tests/test_get_sock_opt.rb +27 -20
  91. data/tests/test_handler_check.rb +1 -3
  92. data/tests/test_hc.rb +49 -112
  93. data/tests/test_httpclient.rb +34 -62
  94. data/tests/test_httpclient2.rb +14 -39
  95. data/tests/test_inactivity_timeout.rb +44 -40
  96. data/tests/test_kb.rb +26 -52
  97. data/tests/test_ltp.rb +27 -71
  98. data/tests/test_ltp2.rb +1 -30
  99. data/tests/test_next_tick.rb +2 -31
  100. data/tests/test_object_protocol.rb +8 -9
  101. data/tests/test_pause.rb +45 -37
  102. data/tests/test_pending_connect_timeout.rb +42 -38
  103. data/tests/test_pool.rb +128 -0
  104. data/tests/test_process_watch.rb +37 -37
  105. data/tests/test_processes.rb +92 -110
  106. data/tests/test_proxy_connection.rb +137 -61
  107. data/tests/test_pure.rb +30 -67
  108. data/tests/test_queue.rb +10 -4
  109. data/tests/test_resolver.rb +55 -0
  110. data/tests/test_running.rb +1 -29
  111. data/tests/test_sasl.rb +8 -33
  112. data/tests/test_send_file.rb +163 -188
  113. data/tests/test_servers.rb +12 -55
  114. data/tests/test_shutdown_hooks.rb +23 -0
  115. data/tests/test_smtpclient.rb +1 -29
  116. data/tests/test_smtpserver.rb +1 -29
  117. data/tests/test_spawn.rb +2 -31
  118. data/tests/test_ssl_args.rb +9 -10
  119. data/tests/test_ssl_methods.rb +1 -3
  120. data/tests/test_ssl_verify.rb +63 -63
  121. data/tests/test_threaded_resource.rb +53 -0
  122. data/tests/test_tick_loop.rb +59 -0
  123. data/tests/test_timers.rb +52 -91
  124. data/tests/test_ud.rb +1 -29
  125. data/tests/test_unbind_reason.rb +31 -0
  126. metadata +113 -70
  127. data/README +0 -82
  128. data/docs/DEFERRABLES +0 -133
  129. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  130. data/docs/SMTP +0 -2
  131. data/docs/SPAWNED_PROCESSES +0 -89
  132. data/ext/cplusplus.cpp +0 -202
  133. data/ext/emwin.cpp +0 -300
  134. data/ext/emwin.h +0 -94
  135. data/ext/epoll.cpp +0 -26
  136. data/ext/epoll.h +0 -25
  137. data/ext/eventmachine_cpp.h +0 -96
  138. data/ext/files.cpp +0 -94
  139. data/ext/files.h +0 -65
  140. data/ext/sigs.cpp +0 -89
  141. data/ext/sigs.h +0 -32
  142. data/java/src/com/rubyeventmachine/application/Application.java +0 -194
  143. data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  144. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  145. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  146. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  147. data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  148. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  149. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  150. data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  151. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  152. data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  153. data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  154. data/lib/evma/callback.rb +0 -32
  155. data/lib/evma/container.rb +0 -75
  156. data/lib/evma/factory.rb +0 -77
  157. data/lib/evma/protocol.rb +0 -87
  158. data/lib/evma/reactor.rb +0 -48
  159. data/lib/evma.rb +0 -32
  160. data/setup.rb +0 -1585
  161. data/tests/test_errors.rb +0 -82
  162. data/tests/testem.rb +0 -31
  163. data/web/whatis +0 -7
  164. /data/{docs/GNU → GNU} +0 -0
  165. /data/{docs/COPYING → LICENSE} +0 -0
  166. /data/docs/{ChangeLog → old/ChangeLog} +0 -0
  167. /data/docs/{EPOLL → old/EPOLL} +0 -0
  168. /data/docs/{INSTALL → old/INSTALL} +0 -0
  169. /data/docs/{LEGAL → old/LEGAL} +0 -0
  170. /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
  171. /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
  172. /data/docs/{TODO → old/TODO} +0 -0
  173. /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
  174. /data/examples/{helper.rb → old/helper.rb} +0 -0
data/tests/test_kb.rb CHANGED
@@ -1,60 +1,34 @@
1
- # $Id$
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
- def setup
34
- end
35
-
36
- def teardown
37
- end
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
- module KbHandler
40
- include EM::Protocols::LineText2
41
- def receive_line d
42
- EM::stop if d == "STOP"
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
- end
26
+ else
27
+ warn "EM.open_keyboard not implemented, skipping tests in #{__FILE__}"
45
28
 
46
- # This test doesn't actually do anything useful but is here to
47
- # illustrate the usage. If you removed the timer and ran this test
48
- # by itself on a console, and then typed into the console, it would
49
- # work.
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
- # $Id$
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
- TestHost = "127.0.0.1"
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
- EventMachine.run {
63
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
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
- EventMachine.add_timer(4) {assert(false, "test timed out")}
35
+ setup_timeout
67
36
 
68
- EventMachine.connect TestHost, TestPort, StopClient do |c|
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 < EventMachine::Protocols::LineAndTextProtocol
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
- EventMachine.run {
87
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
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
- EventMachine.add_timer(4) {assert(false, "test timed out")}
59
+ setup_timeout
91
60
 
92
- EventMachine.connect TestHost, TestPort, StopClient do |c|
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 < EventMachine::Protocols::LineAndTextProtocol
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
- lines_received = []
124
- text_received = []
125
- EventMachine.run {
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
- EventMachine.connect TestHost, TestPort, StopClient do |c|
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 < EventMachine::Protocols::LineAndTextProtocol
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
- lines_received = []
164
- text_received = []
165
- EventMachine.run {
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
- EventMachine.connect TestHost, TestPort, StopClient do |c|
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.2) { c.close_connection_after_writing }
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
- # $Id$
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
 
@@ -1,33 +1,4 @@
1
- # $Id$
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.2) { EM.stop } }
35
+ EM.run { EM.add_timer(0.01) { EM.stop } }
65
36
  assert x
66
37
  end
67
38
 
@@ -1,11 +1,6 @@
1
- $:.unshift "../lib"
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 Host, Port, Server
31
- EM.connect Host, Port, Client
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
- $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
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
- TestHost = "127.0.0.1"
8
- TestPort = 9070
9
-
10
- def setup
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
- def test_pause_resume
21
- test = self
22
- server = nil
13
+ def test_pause_resume
14
+ server = nil
23
15
 
24
- s_rx = c_rx = 0
16
+ s_rx = c_rx = 0
25
17
 
26
- EM.run do
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.add_timer(1) do
52
- test.assert_equal 1, s_rx
53
- test.assert_equal 0, c_rx
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
- # resume server, queued outgoing and incoming data will be flushed
57
- server.resume
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
- test.assert ! server.paused?
56
+ # resume server, queued outgoing and incoming data will be flushed
57
+ server.resume
60
58
 
61
- EM.add_timer(1) do
62
- test.assert server.paused?
63
- test.assert s_rx >= 2
64
- test.assert c_rx >= 1
65
- EM.stop_event_loop
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
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestPendingConnectTimeout < Test::Unit::TestCase
6
4
 
7
- def test_default
8
- $timeout = nil
9
- EM.run {
10
- c = EM.connect("127.0.0.1", 54321)
11
- $timeout = c.pending_connect_timeout
12
- EM.stop
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
- module TimeoutHandler
31
- def unbind
32
- EM.stop
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
- def test_for_real
37
- $timeout = nil
38
- EM.run {
39
- EM.heartbeat_interval = 0.1
40
- $start = Time.now
41
- c = EM.connect("1.2.3.4", 54321, TimeoutHandler)
42
- c.pending_connect_timeout = 5
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
- assert_in_delta(5, (Time.now - $start), 0.3)
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