eventmachine 0.12.2 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +191 -0
- data/{COPYING → docs/COPYING} +0 -0
- data/docs/ChangeLog +183 -0
- data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
- data/{EPOLL → docs/EPOLL} +0 -0
- data/{GNU → docs/GNU} +0 -0
- data/docs/INSTALL +15 -0
- data/{KEYBOARD → docs/KEYBOARD} +0 -0
- data/{LEGAL → docs/LEGAL} +0 -0
- data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
- data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
- data/{README → docs/README} +1 -1
- data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
- data/{SMTP → docs/SMTP} +1 -1
- data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
- data/{TODO → docs/TODO} +1 -1
- data/ext/binder.cpp +1 -1
- data/ext/binder.h +1 -1
- data/ext/cmain.cpp +65 -74
- data/ext/cplusplus.cpp +1 -1
- data/ext/ed.cpp +41 -25
- data/ext/ed.h +10 -3
- data/ext/em.cpp +39 -12
- data/ext/em.h +13 -1
- data/ext/emwin.cpp +1 -1
- data/ext/emwin.h +1 -1
- data/ext/epoll.cpp +1 -1
- data/ext/epoll.h +1 -1
- data/ext/eventmachine.h +1 -1
- data/ext/eventmachine_cpp.h +1 -1
- data/ext/extconf.rb +86 -139
- data/ext/fastfilereader/extconf.rb +161 -0
- data/ext/fastfilereader/mapper.cpp +202 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +1 -1
- data/ext/files.h +1 -1
- data/ext/kb.cpp +1 -1
- data/ext/page.cpp +1 -1
- data/ext/page.h +1 -1
- data/ext/pipe.cpp +14 -7
- data/ext/project.h +1 -1
- data/ext/rubymain.cpp +56 -2
- data/ext/sigs.cpp +1 -1
- data/ext/sigs.h +1 -1
- data/ext/ssl.cpp +1 -1
- data/ext/ssl.h +1 -1
- data/java/src/com/rubyeventmachine/Application.java +196 -0
- data/java/src/com/rubyeventmachine/Connection.java +74 -0
- data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
- data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
- data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
- data/java/src/com/rubyeventmachine/Timer.java +54 -0
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
- data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
- data/lib/em/deferrable.rb +1 -1
- data/lib/em/eventable.rb +1 -1
- data/lib/em/future.rb +1 -1
- data/lib/em/messages.rb +1 -1
- data/lib/em/processes.rb +1 -1
- data/lib/em/spawnable.rb +1 -1
- data/lib/em/streamer.rb +1 -1
- data/lib/eventmachine.rb +138 -116
- data/lib/eventmachine_version.rb +2 -2
- data/lib/evma.rb +1 -1
- data/lib/evma/callback.rb +1 -1
- data/lib/evma/container.rb +1 -1
- data/lib/evma/factory.rb +1 -1
- data/lib/evma/protocol.rb +1 -1
- data/lib/evma/reactor.rb +1 -1
- data/lib/jeventmachine.rb +7 -2
- data/lib/pr_eventmachine.rb +2 -2
- data/lib/protocols/buftok.rb +1 -1
- data/lib/protocols/header_and_content.rb +1 -1
- data/lib/protocols/httpcli2.rb +16 -6
- data/lib/protocols/httpclient.rb +7 -1
- data/lib/protocols/line_and_text.rb +6 -2
- data/lib/protocols/linetext2.rb +12 -14
- data/lib/protocols/postgres.rb +1 -1
- data/lib/protocols/saslauth.rb +1 -1
- data/lib/protocols/smtpclient.rb +1 -1
- data/lib/protocols/smtpserver.rb +36 -23
- data/lib/protocols/stomp.rb +24 -1
- data/lib/protocols/tcptest.rb +1 -1
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +192 -0
- data/tests/test_attach.rb +1 -1
- data/tests/test_basic.rb +65 -12
- data/tests/test_defer.rb +13 -29
- data/tests/test_epoll.rb +16 -21
- data/tests/test_errors.rb +1 -1
- data/tests/test_eventables.rb +4 -5
- data/tests/test_exc.rb +1 -1
- data/tests/test_futures.rb +1 -1
- data/tests/test_hc.rb +185 -236
- data/tests/test_httpclient.rb +1 -1
- data/tests/test_httpclient2.rb +28 -6
- data/tests/test_kb.rb +2 -2
- data/tests/test_ltp.rb +139 -141
- data/tests/test_ltp2.rb +1 -1
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_processes.rb +1 -1
- data/tests/test_pure.rb +3 -2
- data/tests/test_running.rb +1 -1
- data/tests/test_sasl.rb +1 -1
- data/tests/test_send_file.rb +56 -51
- data/tests/test_servers.rb +26 -36
- data/tests/test_smtpclient.rb +46 -44
- data/tests/test_smtpserver.rb +1 -1
- data/tests/test_spawn.rb +1 -1
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_timers.rb +15 -9
- data/tests/test_ud.rb +1 -1
- data/tests/testem.rb +30 -4
- metadata +69 -34
data/tests/test_epoll.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id
|
1
|
+
# $Id$
|
2
2
|
#
|
3
3
|
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
4
|
# Homepage:: http://rubyeventmachine.com
|
@@ -28,20 +28,12 @@
|
|
28
28
|
# the result is a very confusing error message.
|
29
29
|
#
|
30
30
|
|
31
|
-
$:.unshift "../lib"
|
32
31
|
require 'eventmachine'
|
33
32
|
require 'test/unit'
|
34
33
|
|
35
34
|
|
36
35
|
class TestEpoll < Test::Unit::TestCase
|
37
36
|
|
38
|
-
def setup
|
39
|
-
end
|
40
|
-
|
41
|
-
def teardown
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
37
|
module TestEchoServer
|
46
38
|
def receive_data data
|
47
39
|
send_data data
|
@@ -69,7 +61,7 @@ class TestEpoll < Test::Unit::TestCase
|
|
69
61
|
# On most systems, the default value is 1024.
|
70
62
|
# Java doesn't (currently) implement this.
|
71
63
|
def test_rlimit
|
72
|
-
unless RUBY_PLATFORM =~ /java/
|
64
|
+
unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
|
73
65
|
a = EM.set_descriptor_table_size
|
74
66
|
assert( a <= 1024 )
|
75
67
|
a = EM.set_descriptor_table_size( 1024 )
|
@@ -97,16 +89,16 @@ class TestEpoll < Test::Unit::TestCase
|
|
97
89
|
assert_equal(100, $max)
|
98
90
|
end
|
99
91
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
92
|
+
def test_defer
|
93
|
+
n = 0
|
94
|
+
work_proc = proc {n += 1}
|
95
|
+
callback_proc = proc {EM.stop}
|
96
|
+
EM.epoll
|
97
|
+
EM.run {
|
98
|
+
EM.defer work_proc, callback_proc
|
99
|
+
}
|
100
|
+
assert_equal( 1, n )
|
101
|
+
end unless RUBY_VERSION >= '1.9.0'
|
110
102
|
|
111
103
|
|
112
104
|
module TestDatagramServer
|
@@ -140,6 +132,7 @@ class TestEpoll < Test::Unit::TestCase
|
|
140
132
|
|
141
133
|
|
142
134
|
def test_unix_domain
|
135
|
+
fn = "/tmp/xxx.chain"
|
143
136
|
EM.epoll
|
144
137
|
s = EM.set_descriptor_table_size 60000
|
145
138
|
EM.run {
|
@@ -151,7 +144,6 @@ class TestEpoll < Test::Unit::TestCase
|
|
151
144
|
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
|
152
145
|
# work on Windows anyway.
|
153
146
|
#
|
154
|
-
fn = "/tmp/xxx.chain"
|
155
147
|
File.unlink(fn) if File.exist?(fn)
|
156
148
|
EM.start_unix_domain_server fn, TestEchoServer
|
157
149
|
$n = 0
|
@@ -159,9 +151,12 @@ class TestEpoll < Test::Unit::TestCase
|
|
159
151
|
50.times {
|
160
152
|
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
|
161
153
|
}
|
154
|
+
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
|
162
155
|
}
|
163
156
|
assert_equal(0, $n)
|
164
157
|
assert_equal(50, $max)
|
158
|
+
ensure
|
159
|
+
File.unlink(fn) if File.exist?(fn)
|
165
160
|
end
|
166
161
|
|
167
162
|
end
|
data/tests/test_errors.rb
CHANGED
data/tests/test_eventables.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id
|
1
|
+
# $Id$
|
2
2
|
#
|
3
3
|
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
4
|
# Homepage:: http://rubyeventmachine.com
|
@@ -27,10 +27,6 @@
|
|
27
27
|
$:.unshift "../lib"
|
28
28
|
require 'eventmachine'
|
29
29
|
|
30
|
-
require 'test/unit/testsuite'
|
31
|
-
require 'test/unit/ui/console/testrunner'
|
32
|
-
|
33
|
-
|
34
30
|
class TestEventables < Test::Unit::TestCase
|
35
31
|
|
36
32
|
class EvTest
|
@@ -68,6 +64,9 @@ end
|
|
68
64
|
#--------------------------------------
|
69
65
|
|
70
66
|
if __FILE__ == $0
|
67
|
+
require 'test/unit/testsuite'
|
68
|
+
require 'test/unit/ui/console/testrunner'
|
69
|
+
|
71
70
|
runner = Test::Unit::UI::Console::TestRunner
|
72
71
|
suite = Test::Unit::TestSuite.new("name")
|
73
72
|
ObjectSpace.each_object(Class) do |testcase|
|
data/tests/test_exc.rb
CHANGED
data/tests/test_futures.rb
CHANGED
data/tests/test_hc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id
|
1
|
+
# $Id$
|
2
2
|
#
|
3
3
|
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
4
|
# Homepage:: http://rubyeventmachine.com
|
@@ -24,246 +24,195 @@
|
|
24
24
|
#
|
25
25
|
#
|
26
26
|
|
27
|
-
$:.unshift "../lib"
|
27
|
+
# $:.unshift "../lib"
|
28
28
|
require 'eventmachine'
|
29
|
-
require 'socket'
|
30
29
|
require 'test/unit'
|
31
30
|
|
32
|
-
# This doesn't completely work under Ruby 1.9.
|
33
|
-
# Part of it is thread race conditions. I added some sleeps to make these
|
34
|
-
# tests work. Native threads do strange things when you do I/O on them.
|
35
|
-
#
|
36
|
-
# And it's even worse in Java, where I/O on native threads doesn't seem
|
37
|
-
# to be reliable at all.
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
31
|
class TestHeaderAndContentProtocol < Test::Unit::TestCase
|
42
32
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#--------------------------------------------------------------------
|
48
|
-
|
49
|
-
class SimpleTest < EventMachine::Protocols::HeaderAndContentProtocol
|
50
|
-
attr_reader :first_header, :my_headers, :request
|
51
|
-
|
52
|
-
def receive_first_header_line hdr
|
53
|
-
@first_header ||= []
|
54
|
-
@first_header << hdr
|
55
|
-
end
|
56
|
-
def receive_headers hdrs
|
57
|
-
@my_headers ||= []
|
58
|
-
@my_headers << hdrs
|
59
|
-
end
|
60
|
-
def receive_request hdrs, content
|
61
|
-
@request ||= []
|
62
|
-
@request << [hdrs, content]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def test_no_content
|
68
|
-
Thread.abort_on_exception = true
|
69
|
-
the_connection = nil
|
70
|
-
EventMachine.run {
|
71
|
-
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
72
|
-
the_connection = conn
|
73
|
-
end
|
74
|
-
EventMachine.add_timer(4) {raise "test timed out"}
|
75
|
-
|
76
|
-
pr = proc {
|
77
|
-
t = TCPSocket.new TestHost, TestPort
|
78
|
-
t.write [ "aaa\n", "bbb\r\n", "ccc\n", "\n" ].join
|
79
|
-
t.close
|
80
|
-
}
|
81
|
-
|
82
|
-
if RUBY_PLATFORM =~ /java/i
|
83
|
-
pr.call
|
84
|
-
EM.add_timer(0.5) {EM.stop}
|
85
|
-
else
|
86
|
-
EventMachine.defer proc {
|
87
|
-
pr.call
|
88
|
-
if RUBY_VERSION =~ /\A1\.9\./
|
89
|
-
sleep 0.1
|
90
|
-
STDERR.puts "Introducing extraneous sleep for Ruby 1.9"
|
91
|
-
end
|
92
|
-
}, proc {
|
93
|
-
EventMachine.stop
|
94
|
-
}
|
95
|
-
end
|
96
|
-
}
|
97
|
-
assert_equal( ["aaa"], the_connection.first_header )
|
98
|
-
assert_equal( [%w(aaa bbb ccc)], the_connection.my_headers )
|
99
|
-
assert_equal( [[%w(aaa bbb ccc), ""]], the_connection.request )
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
def test_content
|
106
|
-
Thread.abort_on_exception = true
|
107
|
-
the_connection = nil
|
108
|
-
content = "A" * 50
|
109
|
-
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
110
|
-
EventMachine.run {
|
111
|
-
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
112
|
-
the_connection = conn
|
113
|
-
end
|
114
|
-
EventMachine.add_timer(4) {raise "test timed out"}
|
115
|
-
|
116
|
-
pr = proc {
|
117
|
-
t = TCPSocket.new TestHost, TestPort
|
118
|
-
headers.each {|h| t.write "#{h}\r\n" }
|
119
|
-
t.write "\n"
|
120
|
-
t.write content
|
121
|
-
t.close
|
122
|
-
}
|
33
|
+
TestHost = "127.0.0.1"
|
34
|
+
TestPort = 8905
|
123
35
|
|
124
|
-
|
125
|
-
|
126
|
-
pr.call
|
127
|
-
EM.add_timer(0.5) {EM.stop}
|
128
|
-
else
|
129
|
-
EventMachine.defer proc {
|
130
|
-
pr.call
|
131
|
-
if RUBY_VERSION =~ /\A1\.9\./
|
132
|
-
sleep 0.1
|
133
|
-
STDERR.puts "Introducing extraneous sleep for Ruby 1.9"
|
134
|
-
end
|
135
|
-
}, proc {
|
136
|
-
EM.stop
|
137
|
-
}
|
138
|
-
end
|
139
|
-
}
|
140
|
-
assert_equal( ["aaa"], the_connection.first_header )
|
141
|
-
assert_equal( [headers], the_connection.my_headers )
|
142
|
-
assert_equal( [[headers, content]], the_connection.request )
|
143
|
-
end
|
36
|
+
class SimpleTest < EventMachine::Protocols::HeaderAndContentProtocol
|
37
|
+
attr_reader :first_header, :my_headers, :request
|
144
38
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
Thread.abort_on_exception = true
|
149
|
-
the_connection = nil
|
150
|
-
content = "A" * 50
|
151
|
-
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
152
|
-
EventMachine.run {
|
153
|
-
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
154
|
-
the_connection = conn
|
155
|
-
end
|
156
|
-
EventMachine.add_timer(4) {raise "test timed out"}
|
157
|
-
|
158
|
-
pr = proc {
|
159
|
-
t = TCPSocket.new TestHost, TestPort
|
160
|
-
5.times {
|
161
|
-
headers.each {|h| t.write "#{h}\r\n" }
|
162
|
-
t.write "\n"
|
163
|
-
t.write content
|
164
|
-
}
|
165
|
-
t.close
|
166
|
-
}
|
167
|
-
|
168
|
-
if RUBY_PLATFORM =~ /java/i
|
169
|
-
pr.call
|
170
|
-
EM.add_timer(1) {EM.stop}
|
171
|
-
else
|
172
|
-
EventMachine.defer proc {
|
173
|
-
pr.call
|
174
|
-
if RUBY_VERSION =~ /\A1\.9\./
|
175
|
-
sleep 0.1
|
176
|
-
STDERR.puts "Introducing extraneous sleep for Ruby 1.9"
|
177
|
-
end
|
178
|
-
}, proc {
|
179
|
-
EventMachine.stop
|
180
|
-
}
|
181
|
-
end
|
182
|
-
}
|
183
|
-
assert_equal( ["aaa"] * 5, the_connection.first_header )
|
184
|
-
assert_equal( [headers] * 5, the_connection.my_headers )
|
185
|
-
assert_equal( [[headers, content]] * 5, the_connection.request )
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
|
-
def x_test_multiple_content_length_headers
|
190
|
-
# This is supposed to throw a RuntimeError but it throws a C++ exception instead.
|
191
|
-
Thread.abort_on_exception = true
|
192
|
-
the_connection = nil
|
193
|
-
content = "A" * 50
|
194
|
-
headers = ["aaa", "bbb", ["Content-length: #{content.length}"]*2, "ccc"].flatten
|
195
|
-
EventMachine.run {
|
196
|
-
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
197
|
-
the_connection = conn
|
198
|
-
end
|
199
|
-
EventMachine.add_timer(4) {raise "test timed out"}
|
200
|
-
EventMachine.defer proc {
|
201
|
-
t = TCPSocket.new TestHost, TestPort
|
202
|
-
headers.each {|h| t.write "#{h}\r\n" }
|
203
|
-
t.write "\n"
|
204
|
-
t.write content
|
205
|
-
t.close
|
206
|
-
}, proc {
|
207
|
-
EventMachine.stop
|
208
|
-
}
|
209
|
-
}
|
39
|
+
def receive_first_header_line hdr
|
40
|
+
@first_header ||= []
|
41
|
+
@first_header << hdr
|
210
42
|
end
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
43
|
+
def receive_headers hdrs
|
44
|
+
@my_headers ||= []
|
45
|
+
@my_headers << hdrs
|
46
|
+
end
|
47
|
+
def receive_request hdrs, content
|
48
|
+
@request ||= []
|
49
|
+
@request << [hdrs, content]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_no_content
|
54
|
+
the_connection = nil
|
55
|
+
EventMachine.run {
|
56
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
57
|
+
the_connection = conn
|
58
|
+
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
|
65
|
+
|
66
|
+
def post_init
|
67
|
+
send_data [ "aaa\n", "bbb\r\n", "ccc\n", "\n" ].join
|
68
|
+
close_connection_after_writing
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
EventMachine.connect( TestHost, TestPort, client )
|
73
|
+
}
|
74
|
+
assert_equal( ["aaa"], the_connection.first_header )
|
75
|
+
assert_equal( [%w(aaa bbb ccc)], the_connection.my_headers )
|
76
|
+
assert_equal( [[%w(aaa bbb ccc), ""]], the_connection.request )
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_content
|
80
|
+
the_connection = nil
|
81
|
+
content = "A" * 50
|
82
|
+
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
83
|
+
EventMachine.run {
|
84
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
85
|
+
the_connection = conn
|
86
|
+
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
|
96
|
+
|
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
|
103
|
+
end
|
104
|
+
|
105
|
+
EventMachine.connect( TestHost, TestPort, client )
|
106
|
+
|
107
|
+
}
|
108
|
+
assert_equal( ["aaa"], the_connection.first_header )
|
109
|
+
assert_equal( [headers], the_connection.my_headers )
|
110
|
+
assert_equal( [[headers, content]], the_connection.request )
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_several_requests
|
114
|
+
the_connection = nil
|
115
|
+
content = "A" * 50
|
116
|
+
headers = ["aaa", "bbb", "Content-length: #{content.length}", "ccc"]
|
117
|
+
EventMachine.run {
|
118
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
119
|
+
the_connection = conn
|
120
|
+
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
|
130
|
+
|
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
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
EventMachine.connect( TestHost, TestPort, client )
|
142
|
+
}
|
143
|
+
assert_equal( ["aaa"] * 5, the_connection.first_header )
|
144
|
+
assert_equal( [headers] * 5, the_connection.my_headers )
|
145
|
+
assert_equal( [[headers, content]] * 5, the_connection.request )
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# def x_test_multiple_content_length_headers
|
150
|
+
# # This is supposed to throw a RuntimeError but it throws a C++ exception instead.
|
151
|
+
# the_connection = nil
|
152
|
+
# content = "A" * 50
|
153
|
+
# headers = ["aaa", "bbb", ["Content-length: #{content.length}"]*2, "ccc"].flatten
|
154
|
+
# EventMachine.run {
|
155
|
+
# EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
156
|
+
# the_connection = conn
|
157
|
+
# end
|
158
|
+
# EventMachine.add_timer(4) {raise "test timed out"}
|
159
|
+
# test_proc = proc {
|
160
|
+
# t = TCPSocket.new TestHost, TestPort
|
161
|
+
# headers.each {|h| t.write "#{h}\r\n" }
|
162
|
+
# t.write "\n"
|
163
|
+
# t.write content
|
164
|
+
# t.close
|
165
|
+
# }
|
166
|
+
# EventMachine.defer test_proc, proc {
|
167
|
+
# EventMachine.stop
|
168
|
+
# }
|
169
|
+
# }
|
170
|
+
# end
|
171
|
+
|
172
|
+
def test_interpret_headers
|
173
|
+
the_connection = nil
|
174
|
+
content = "A" * 50
|
175
|
+
headers = [
|
176
|
+
"GET / HTTP/1.0",
|
177
|
+
"Accept: aaa",
|
178
|
+
"User-Agent: bbb",
|
179
|
+
"Host: ccc",
|
180
|
+
"x-tempest-header:ddd"
|
181
|
+
]
|
182
|
+
|
183
|
+
EventMachine.run {
|
184
|
+
EventMachine.start_server( TestHost, TestPort, SimpleTest ) do |conn|
|
185
|
+
the_connection = conn
|
186
|
+
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
|
196
|
+
|
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
|
203
|
+
end
|
204
|
+
|
205
|
+
EventMachine.connect( TestHost, TestPort, client )
|
206
|
+
}
|
207
|
+
|
208
|
+
hsh = the_connection.headers_2_hash( the_connection.my_headers.shift )
|
209
|
+
expect = {
|
210
|
+
:accept => "aaa",
|
211
|
+
:user_agent => "bbb",
|
212
|
+
:host => "ccc",
|
213
|
+
:x_tempest_header => "ddd"
|
214
|
+
}
|
215
|
+
assert_equal(expect, hsh)
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|