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_hc.rb CHANGED
@@ -1,39 +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
- # $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
1
+ require 'em_test_helper'
30
2
 
31
3
  class TestHeaderAndContentProtocol < Test::Unit::TestCase
32
4
 
33
- TestHost = "127.0.0.1"
34
- TestPort = 8905
35
-
36
- class SimpleTest < EventMachine::Protocols::HeaderAndContentProtocol
5
+ class SimpleTest < EM::P::HeaderAndContentProtocol
37
6
  attr_reader :first_header, :my_headers, :request
38
7
 
39
8
  def receive_first_header_line hdr
@@ -49,27 +18,29 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
49
18
  @request << [hdrs, content]
50
19
  end
51
20
  end
21
+
22
+ class StopOnUnbind < EM::Connection
23
+ def unbind
24
+ EM.add_timer(0.01) { EM.stop }
25
+ end
26
+ end
27
+
28
+ def setup
29
+ @port = next_port
30
+ end
52
31
 
53
32
  def test_no_content
54
33
  the_connection = nil
55
- EventMachine.run {
56
- EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
34
+ EM.run {
35
+ EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
57
36
  the_connection = conn
58
37
  end
59
- EventMachine.add_timer(4) {raise "test timed out"}
60
-
61
- client = Module.new do
62
- def unbind
63
- EM.add_timer(0.1) { EM.stop }
64
- end
38
+ setup_timeout
65
39
 
66
- def post_init
67
- send_data [ "aaa\n", "bbb\r\n", "ccc\n", "\n" ].join
68
- close_connection_after_writing
69
- end
40
+ EM.connect "127.0.0.1", @port, StopOnUnbind do |c|
41
+ c.send_data [ "aaa\n", "bbb\r\n", "ccc\n", "\n" ].join
42
+ c.close_connection_after_writing
70
43
  end
71
-
72
- EventMachine.connect( TestHost, TestPort, client )
73
44
  }
74
45
  assert_equal( ["aaa"], the_connection.first_header )
75
46
  assert_equal( [%w(aaa bbb ccc)], the_connection.my_headers )
@@ -80,30 +51,18 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
80
51
  the_connection = nil
81
52
  content = "A" * 50
82
53
  headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
83
- EventMachine.run {
84
- EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
54
+ EM.run {
55
+ EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
85
56
  the_connection = conn
86
57
  end
87
- EventMachine.add_timer(4) { assert(false, 'test timeout'); EM.stop }
88
-
89
- client = Module.new do
90
- define_method(:headers) { headers }
91
- define_method(:content) { content }
92
-
93
- def unbind
94
- EM.add_timer(0.1) { EM.stop }
95
- end
58
+ setup_timeout
96
59
 
97
- def post_init
98
- headers.each { |h| send_data "#{h}\r\n" }
99
- send_data "\n"
100
- send_data content
101
- close_connection_after_writing
102
- end
60
+ EM.connect "127.0.0.1", @port, StopOnUnbind do |c|
61
+ headers.each { |h| c.send_data "#{h}\r\n" }
62
+ c.send_data "\n"
63
+ c.send_data content
64
+ c.close_connection_after_writing
103
65
  end
104
-
105
- EventMachine.connect( TestHost, TestPort, client )
106
-
107
66
  }
108
67
  assert_equal( ["aaa"], the_connection.first_header )
109
68
  assert_equal( [headers], the_connection.my_headers )
@@ -114,31 +73,20 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
114
73
  the_connection = nil
115
74
  content = "A" * 50
116
75
  headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
117
- EventMachine.run {
118
- EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
76
+ EM.run {
77
+ EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
119
78
  the_connection = conn
120
79
  end
121
- EventMachine.add_timer(4) { assert(false, 'test timeout'); EM.stop }
122
-
123
- client = Module.new do
124
- define_method(:headers) { headers }
125
- define_method(:content) { content }
126
-
127
- def unbind
128
- EM.add_timer(0.1) { EM.stop }
129
- end
80
+ setup_timeout
130
81
 
131
- def post_init
132
- 5.times do
133
- headers.each { |h| send_data "#{h}\r\n" }
134
- send_data "\n"
135
- send_data content
136
- end
137
- close_connection_after_writing
82
+ EM.connect( "127.0.0.1", @port, StopOnUnbind ) do |c|
83
+ 5.times do
84
+ headers.each { |h| c.send_data "#{h}\r\n" }
85
+ c.send_data "\n"
86
+ c.send_data content
138
87
  end
88
+ c.close_connection_after_writing
139
89
  end
140
-
141
- EventMachine.connect( TestHost, TestPort, client )
142
90
  }
143
91
  assert_equal( ["aaa"] * 5, the_connection.first_header )
144
92
  assert_equal( [headers] * 5, the_connection.my_headers )
@@ -151,20 +99,20 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
151
99
  # the_connection = nil
152
100
  # content = "A" * 50
153
101
  # headers = ["aaa", "bbb", ["Content-length: #{content.length}"]*2, "ccc"].flatten
154
- # EventMachine.run {
155
- # EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
102
+ # EM.run {
103
+ # EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
156
104
  # the_connection = conn
157
105
  # end
158
- # EventMachine.add_timer(4) {raise "test timed out"}
106
+ # EM.add_timer(4) {raise "test timed out"}
159
107
  # test_proc = proc {
160
- # t = TCPSocket.new TestHost, TestPort
108
+ # t = TCPSocket.new "127.0.0.1", @port
161
109
  # headers.each {|h| t.write "#{h}\r\n" }
162
110
  # t.write "\n"
163
111
  # t.write content
164
112
  # t.close
165
113
  # }
166
- # EventMachine.defer test_proc, proc {
167
- # EventMachine.stop
114
+ # EM.defer test_proc, proc {
115
+ # EM.stop
168
116
  # }
169
117
  # }
170
118
  # end
@@ -180,29 +128,18 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
180
128
  "x-tempest-header:ddd"
181
129
  ]
182
130
 
183
- EventMachine.run {
184
- EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
131
+ EM.run {
132
+ EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
185
133
  the_connection = conn
186
134
  end
187
- EventMachine.add_timer(4) {raise "test timed out"}
188
-
189
- client = Module.new do
190
- define_method(:headers) { headers }
191
- define_method(:content) { content }
192
-
193
- def unbind
194
- EM.add_timer(0.1) { EM.stop }
195
- end
135
+ setup_timeout
196
136
 
197
- def post_init
198
- headers.each { |h| send_data "#{h}\r\n" }
199
- send_data "\n"
200
- send_data content
201
- close_connection_after_writing
202
- end
137
+ EM.connect( "127.0.0.1", @port, StopOnUnbind ) do |c|
138
+ headers.each { |h| c.send_data "#{h}\r\n" }
139
+ c.send_data "\n"
140
+ c.send_data content
141
+ c.close_connection_after_writing
203
142
  end
204
-
205
- EventMachine.connect( TestHost, TestPort, client )
206
143
  }
207
144
 
208
145
  hsh = the_connection.headers_2_hash( the_connection.my_headers.shift )
@@ -1,32 +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
- $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
1
+ require 'em_test_helper'
30
2
 
31
3
  class TestHttpClient < Test::Unit::TestCase
32
4
 
@@ -43,13 +15,13 @@ class TestHttpClient < Test::Unit::TestCase
43
15
 
44
16
  def test_http_client
45
17
  ok = false
46
- EventMachine.run {
47
- c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
18
+ EM.run {
19
+ c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
48
20
  c.callback {
49
21
  ok = true
50
- EventMachine.stop
22
+ EM.stop
51
23
  }
52
- c.errback {EventMachine.stop} # necessary, otherwise a failure blocks the test suite forever.
24
+ c.errback {EM.stop} # necessary, otherwise a failure blocks the test suite forever.
53
25
  }
54
26
  assert ok
55
27
  end
@@ -58,10 +30,10 @@ class TestHttpClient < Test::Unit::TestCase
58
30
 
59
31
  def test_http_client_1
60
32
  ok = false
61
- EventMachine.run {
62
- c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
63
- c.callback {ok = true; EventMachine.stop}
64
- c.errback {EventMachine.stop}
33
+ EM.run {
34
+ c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
35
+ c.callback {ok = true; EM.stop}
36
+ c.errback {EM.stop}
65
37
  }
66
38
  assert ok
67
39
  end
@@ -70,13 +42,13 @@ class TestHttpClient < Test::Unit::TestCase
70
42
 
71
43
  def test_http_client_2
72
44
  ok = false
73
- EventMachine.run {
74
- c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
45
+ EM.run {
46
+ c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
75
47
  c.callback {|result|
76
48
  ok = true;
77
- EventMachine.stop
49
+ EM.stop
78
50
  }
79
- c.errback {EventMachine.stop}
51
+ c.errback {EM.stop}
80
52
  }
81
53
  assert ok
82
54
  end
@@ -89,7 +61,7 @@ class TestHttpClient < Test::Unit::TestCase
89
61
  # causing this test to hang. Observe, there was no problem with responses
90
62
  # lacking a content-length, just when the content-length was zero.
91
63
  #
92
- class EmptyContent < EventMachine::Connection
64
+ class EmptyContent < EM::Connection
93
65
  def initialize *args
94
66
  super
95
67
  end
@@ -101,12 +73,12 @@ class TestHttpClient < Test::Unit::TestCase
101
73
 
102
74
  def test_http_empty_content
103
75
  ok = false
104
- EventMachine.run {
105
- EventMachine.start_server "127.0.0.1", 9701, EmptyContent
106
- c = EventMachine::Protocols::HttpClient.send :request, :host => "127.0.0.1", :port => 9701
76
+ EM.run {
77
+ EM.start_server "127.0.0.1", 9701, EmptyContent
78
+ c = silent { EM::P::HttpClient.send :request, :host => "127.0.0.1", :port => 9701 }
107
79
  c.callback {|result|
108
80
  ok = true
109
- EventMachine.stop
81
+ EM.stop
110
82
  }
111
83
  }
112
84
  assert ok
@@ -115,7 +87,7 @@ class TestHttpClient < Test::Unit::TestCase
115
87
 
116
88
  #---------------------------------------
117
89
 
118
- class PostContent < EventMachine::Protocols::LineAndTextProtocol
90
+ class PostContent < EM::P::LineAndTextProtocol
119
91
  def initialize *args
120
92
  super
121
93
  @lines = []
@@ -154,25 +126,25 @@ class TestHttpClient < Test::Unit::TestCase
154
126
  close_connection_after_writing
155
127
  end
156
128
  end
157
-
129
+
158
130
  # TODO, this is WRONG. The handler is asserting an HTTP 1.1 request, but the client
159
131
  # is sending a 1.0 request. Gotta fix the client
160
132
  def test_post
161
133
  response = nil
162
- EventMachine.run {
163
- EventMachine.start_server Localhost, Localport, PostContent
164
- EventMachine.add_timer(2) {raise "timed out"}
165
- c = EventMachine::Protocols::HttpClient.request(
134
+ EM.run {
135
+ EM.start_server Localhost, Localport, PostContent
136
+ setup_timeout(2)
137
+ c = silent { EM::P::HttpClient.request(
166
138
  :host=>Localhost,
167
139
  :port=>Localport,
168
140
  :method=>:post,
169
141
  :request=>"/aaa",
170
142
  :content=>"XYZ",
171
143
  :content_type=>"text/plain"
172
- )
144
+ )}
173
145
  c.callback {|r|
174
146
  response = r
175
- EventMachine.stop
147
+ EM.stop
176
148
  }
177
149
  }
178
150
 
@@ -186,12 +158,12 @@ class TestHttpClient < Test::Unit::TestCase
186
158
  def test_cookie
187
159
  ok = false
188
160
  EM.run {
189
- c = EM::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80, :cookie=>"aaa=bbb"
161
+ c = silent { EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb" }
190
162
  c.callback {|result|
191
163
  ok = true;
192
- EventMachine.stop
164
+ EM.stop
193
165
  }
194
- c.errback {EventMachine.stop}
166
+ c.errback {EM.stop}
195
167
  }
196
168
  assert ok
197
169
  end
@@ -201,16 +173,16 @@ class TestHttpClient < Test::Unit::TestCase
201
173
  def test_version_1_0
202
174
  ok = false
203
175
  EM.run {
204
- c = EM::P::HttpClient.request(
205
- :host => "www.bayshorenetworks.com",
176
+ c = silent { EM::P::HttpClient.request(
177
+ :host => "www.google.com",
206
178
  :port => 80,
207
179
  :version => "1.0"
208
- )
180
+ )}
209
181
  c.callback {|result|
210
182
  ok = true;
211
- EventMachine.stop
183
+ EM.stop
212
184
  }
213
- c.errback {EventMachine.stop}
185
+ c.errback {EM.stop}
214
186
  }
215
187
  assert ok
216
188
  end
@@ -1,32 +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
- $:.unshift "../lib"
28
- require 'eventmachine'
29
- require 'test/unit'
1
+ require 'em_test_helper'
30
2
 
31
3
  class TestHttpClient2 < Test::Unit::TestCase
32
4
  Localhost = "127.0.0.1"
@@ -50,8 +22,10 @@ class TestHttpClient2 < Test::Unit::TestCase
50
22
  def test_connect
51
23
  EM.run {
52
24
  EM.start_server Localhost, Localport, TestServer
53
- http1 = EM::P::HttpClient2.connect Localhost, Localport
54
- http2 = EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
25
+ silent do
26
+ EM::P::HttpClient2.connect Localhost, Localport
27
+ EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
28
+ end
55
29
  EM.stop
56
30
  }
57
31
  end
@@ -61,7 +35,7 @@ class TestHttpClient2 < Test::Unit::TestCase
61
35
  EM.run {
62
36
  EM.start_server Localhost, Localport, TestServer
63
37
  assert_raises( ArgumentError ) {
64
- EM::P::HttpClient2.connect Localhost, "xxx"
38
+ silent { EM::P::HttpClient2.connect Localhost, "xxx" }
65
39
  }
66
40
  EM.stop
67
41
  }
@@ -70,7 +44,7 @@ class TestHttpClient2 < Test::Unit::TestCase
70
44
  def test_bad_server
71
45
  err = nil
72
46
  EM.run {
73
- http = EM::P::HttpClient2.connect Localhost, 9999
47
+ http = silent { EM::P::HttpClient2.connect Localhost, 9999 }
74
48
  d = http.get "/"
75
49
  d.errback { err = true; d.internal_error; EM.stop }
76
50
  }
@@ -80,7 +54,7 @@ class TestHttpClient2 < Test::Unit::TestCase
80
54
  def test_get
81
55
  content = nil
82
56
  EM.run {
83
- http = EM::P::HttpClient2.connect "google.com", 80
57
+ http = silent { EM::P::HttpClient2.connect "google.com", 80 }
84
58
  d = http.get "/"
85
59
  d.callback {
86
60
  content = d.content
@@ -96,7 +70,7 @@ class TestHttpClient2 < Test::Unit::TestCase
96
70
  def _test_get_multiple
97
71
  content = nil
98
72
  EM.run {
99
- http = EM::P::HttpClient2.connect "google.com", 80
73
+ http = silent { EM::P::HttpClient2.connect "google.com", 80 }
100
74
  d = http.get "/"
101
75
  d.callback {
102
76
  e = http.get "/"
@@ -112,7 +86,7 @@ class TestHttpClient2 < Test::Unit::TestCase
112
86
  def test_get_pipeline
113
87
  headers, headers2 = nil, nil
114
88
  EM.run {
115
- http = EM::P::HttpClient2.connect "google.com", 80
89
+ http = silent { EM::P::HttpClient2.connect "google.com", 80 }
116
90
  d = http.get("/")
117
91
  d.callback {
118
92
  headers = d.headers
@@ -121,7 +95,8 @@ class TestHttpClient2 < Test::Unit::TestCase
121
95
  e.callback {
122
96
  headers2 = e.headers
123
97
  }
124
- EM::Timer.new(1) {EM.stop}
98
+ EM.tick_loop { EM.stop if headers && headers2 }
99
+ EM.add_timer(1) { EM.stop }
125
100
  }
126
101
  assert(headers)
127
102
  assert(headers2)
@@ -131,7 +106,7 @@ class TestHttpClient2 < Test::Unit::TestCase
131
106
  def test_authheader
132
107
  EM.run {
133
108
  EM.start_server Localhost, Localport, TestServer
134
- http = EM::P::HttpClient2.connect Localhost, 18842
109
+ http = silent { EM::P::HttpClient2.connect Localhost, 18842 }
135
110
  d = http.get :url=>"/", :authorization=>"Basic xxx"
136
111
  d.callback {EM.stop}
137
112
  d.errback {EM.stop}
@@ -141,7 +116,7 @@ class TestHttpClient2 < Test::Unit::TestCase
141
116
  def test_https_get
142
117
  d = nil
143
118
  EM.run {
144
- http = EM::P::HttpClient2.connect :host => 'www.amazon.com', :port => 443, :ssl => true
119
+ http = silent { EM::P::HttpClient2.connect :host => 'www.apple.com', :port => 443, :ssl => true }
145
120
  d = http.get "/"
146
121
  d.callback {
147
122
  EM.stop
@@ -1,50 +1,54 @@
1
- $:.unshift "../lib"
2
- require 'eventmachine'
3
- require 'test/unit'
1
+ require 'em_test_helper'
4
2
 
5
3
  class TestInactivityTimeout < 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.comm_inactivity_timeout
12
- EM.stop
13
- }
14
-
15
- assert_equal(0.0, $timeout)
16
- end
17
-
18
- def test_set_and_get
19
- $timeout = nil
20
- EM.run {
21
- c = EM.connect("127.0.0.1", 54321)
22
- c.comm_inactivity_timeout = 2.5
23
- $timeout = c.comm_inactivity_timeout
24
- EM.stop
25
- }
26
-
27
- assert_equal(2.5, $timeout)
28
- end
29
-
30
- module TimeoutHandler
31
- def unbind
32
- EM.stop
5
+ if EM.respond_to? :get_comm_inactivity_timeout
6
+ def test_default
7
+ EM.run {
8
+ c = EM.connect("127.0.0.1", 54321)
9
+ assert_equal 0.0, c.comm_inactivity_timeout
10
+ EM.stop
11
+ }
33
12
  end
34
- end
35
13
 
36
- def test_for_real
37
- EM.run {
38
- EM.heartbeat_interval = 0.1
39
- EM.start_server("127.0.0.1", 12345)
40
- EM.add_timer(0.2) {
41
- $start = Time.now
42
- c = EM.connect("127.0.0.1", 12345, TimeoutHandler)
14
+ def test_set_and_get
15
+ EM.run {
16
+ c = EM.connect("127.0.0.1", 54321)
43
17
  c.comm_inactivity_timeout = 2.5
18
+ assert_equal 2.5, c.comm_inactivity_timeout
19
+ EM.stop
44
20
  }
45
- }
21
+ end
46
22
 
47
- assert_in_delta(2.5, (Time.now - $start), 0.3)
48
- end
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.01
36
+ EM.start_server("127.0.0.1", 12345)
37
+ EM.add_timer(0.01) {
38
+ start = Time.now
39
+ c = EM.connect("127.0.0.1", 12345, timeout_handler)
40
+ c.comm_inactivity_timeout = 0.02
41
+ }
42
+ }
49
43
 
44
+ assert_in_delta(0.02, (finish - start), 0.02)
45
+ end
46
+ else
47
+ warn "EM.comm_inactivity_timeout not implemented, skipping tests in #{__FILE__}"
48
+
49
+ # Because some rubies will complain if a TestCase class has no tests
50
+ def test_em_comm_inactivity_timeout_not_implemented
51
+ assert true
52
+ end
53
+ end
50
54
  end