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_hc.rb
CHANGED
@@ -1,39 +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
|
-
# $:.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
|
-
|
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
|
-
|
56
|
-
|
34
|
+
EM.run {
|
35
|
+
EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
|
57
36
|
the_connection = conn
|
58
37
|
end
|
59
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
84
|
-
|
54
|
+
EM.run {
|
55
|
+
EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
|
85
56
|
the_connection = conn
|
86
57
|
end
|
87
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
118
|
-
|
76
|
+
EM.run {
|
77
|
+
EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
|
119
78
|
the_connection = conn
|
120
79
|
end
|
121
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
#
|
155
|
-
#
|
102
|
+
# EM.run {
|
103
|
+
# EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
|
156
104
|
# the_connection = conn
|
157
105
|
# end
|
158
|
-
#
|
106
|
+
# EM.add_timer(4) {raise "test timed out"}
|
159
107
|
# test_proc = proc {
|
160
|
-
# t = TCPSocket.new
|
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
|
-
#
|
167
|
-
#
|
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
|
-
|
184
|
-
|
131
|
+
EM.run {
|
132
|
+
EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn|
|
185
133
|
the_connection = conn
|
186
134
|
end
|
187
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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 )
|
data/tests/test_httpclient.rb
CHANGED
@@ -1,32 +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
|
-
$:.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
|
-
|
47
|
-
c =
|
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
|
-
|
22
|
+
EM.stop
|
51
23
|
}
|
52
|
-
c.errback {
|
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
|
-
|
62
|
-
c =
|
63
|
-
c.callback {ok = true;
|
64
|
-
c.errback {
|
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
|
-
|
74
|
-
c =
|
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
|
-
|
49
|
+
EM.stop
|
78
50
|
}
|
79
|
-
c.errback {
|
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 <
|
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
|
-
|
105
|
-
|
106
|
-
c =
|
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
|
-
|
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 <
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
c =
|
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
|
-
|
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.
|
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
|
-
|
164
|
+
EM.stop
|
193
165
|
}
|
194
|
-
c.errback {
|
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.
|
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
|
-
|
183
|
+
EM.stop
|
212
184
|
}
|
213
|
-
c.errback {
|
185
|
+
c.errback {EM.stop}
|
214
186
|
}
|
215
187
|
assert ok
|
216
188
|
end
|
data/tests/test_httpclient2.rb
CHANGED
@@ -1,32 +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
|
-
$:.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
|
-
|
54
|
-
|
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
|
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.
|
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
|
-
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'test/unit'
|
1
|
+
require 'em_test_helper'
|
4
2
|
|
5
3
|
class TestInactivityTimeout < Test::Unit::TestCase
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
48
|
-
|
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
|