libc-eventmachine 0.12.5.42
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +195 -0
- data/docs/COPYING +60 -0
- data/docs/ChangeLog +211 -0
- data/docs/DEFERRABLES +138 -0
- data/docs/EPOLL +141 -0
- data/docs/GNU +281 -0
- data/docs/INSTALL +15 -0
- data/docs/KEYBOARD +38 -0
- data/docs/LEGAL +25 -0
- data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/docs/PURE_RUBY +77 -0
- data/docs/README +74 -0
- data/docs/RELEASE_NOTES +96 -0
- data/docs/SMTP +9 -0
- data/docs/SPAWNED_PROCESSES +93 -0
- data/docs/TODO +10 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +582 -0
- data/ext/cplusplus.cpp +177 -0
- data/ext/ed.cpp +1522 -0
- data/ext/ed.h +380 -0
- data/ext/em.cpp +1947 -0
- data/ext/em.h +186 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +98 -0
- data/ext/eventmachine_cpp.h +96 -0
- data/ext/extconf.rb +129 -0
- data/ext/fastfilereader/extconf.rb +77 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +82 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +351 -0
- data/ext/project.h +119 -0
- data/ext/rubymain.cpp +858 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +423 -0
- data/ext/ssl.h +90 -0
- 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 +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1920 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/evma.rb +32 -0
- data/lib/jeventmachine.rb +140 -0
- data/lib/pr_eventmachine.rb +1017 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +129 -0
- data/lib/protocols/httpcli2.rb +803 -0
- data/lib/protocols/httpclient.rb +270 -0
- data/lib/protocols/line_and_text.rb +126 -0
- data/lib/protocols/linetext2.rb +161 -0
- data/lib/protocols/memcache.rb +293 -0
- data/lib/protocols/postgres.rb +261 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +556 -0
- data/lib/protocols/stomp.rb +153 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +193 -0
- data/tests/test_attach.rb +83 -0
- data/tests/test_basic.rb +231 -0
- data/tests/test_bind.rb +73 -0
- data/tests/test_connection_count.rb +35 -0
- data/tests/test_defer.rb +47 -0
- data/tests/test_epoll.rb +163 -0
- data/tests/test_error_handler.rb +32 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +77 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_handler_check.rb +37 -0
- data/tests/test_hc.rb +218 -0
- data/tests/test_httpclient.rb +215 -0
- data/tests/test_httpclient2.rb +155 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +188 -0
- data/tests/test_ltp2.rb +320 -0
- data/tests/test_next_tick.rb +109 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +129 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +74 -0
- data/tests/test_send_file.rb +243 -0
- data/tests/test_servers.rb +80 -0
- data/tests/test_smtpclient.rb +83 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_ssl_methods.rb +50 -0
- data/tests/test_timers.rb +148 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +31 -0
- metadata +230 -0
data/tests/test_spawn.rb
ADDED
@@ -0,0 +1,329 @@
|
|
1
|
+
# $Id$
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 25 Aug 2007
|
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
|
+
|
29
|
+
$:.unshift "../lib"
|
30
|
+
require 'eventmachine'
|
31
|
+
require 'test/unit'
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
class TestSpawn < Test::Unit::TestCase
|
36
|
+
|
37
|
+
def setup
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Spawn a process that simply stops the reactor.
|
45
|
+
# Assert that the notification runs after the block that calls it.
|
46
|
+
#
|
47
|
+
def test_stop
|
48
|
+
x = nil
|
49
|
+
EM.run {
|
50
|
+
s = EM.spawn {EM.stop}
|
51
|
+
s.notify
|
52
|
+
x = true
|
53
|
+
}
|
54
|
+
assert x
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Pass a parameter to a spawned process.
|
59
|
+
#
|
60
|
+
def test_parms
|
61
|
+
val = 5
|
62
|
+
EM.run {
|
63
|
+
s = EM.spawn {|v| val *= v; EM.stop}
|
64
|
+
s.notify 3
|
65
|
+
}
|
66
|
+
assert_equal( 15, val )
|
67
|
+
end
|
68
|
+
|
69
|
+
# Pass multiple parameters to a spawned process.
|
70
|
+
#
|
71
|
+
def test_multiparms
|
72
|
+
val = 5
|
73
|
+
EM.run {
|
74
|
+
s = EM.spawn {|v1,v2| val *= (v1 + v2); EM.stop}
|
75
|
+
s.notify 3,4
|
76
|
+
}
|
77
|
+
assert_equal( 35, val )
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# This test demonstrates that a notification does not happen immediately,
|
82
|
+
# but rather is scheduled sometime after the current code path completes.
|
83
|
+
#
|
84
|
+
def test_race
|
85
|
+
x = 0
|
86
|
+
EM.run {
|
87
|
+
s = EM.spawn {x *= 2; EM.stop}
|
88
|
+
s.notify
|
89
|
+
x = 2
|
90
|
+
}
|
91
|
+
assert_equal( 4, x)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Spawn a process and notify it 25 times to run fibonacci
|
96
|
+
# on a pair of global variables.
|
97
|
+
#
|
98
|
+
def test_fibonacci
|
99
|
+
x = 1
|
100
|
+
y = 1
|
101
|
+
EM.run {
|
102
|
+
s = EM.spawn {x,y = y,x+y}
|
103
|
+
25.times {s.notify}
|
104
|
+
|
105
|
+
t = EM.spawn {EM.stop}
|
106
|
+
t.notify
|
107
|
+
}
|
108
|
+
assert_equal( 121393, x)
|
109
|
+
assert_equal( 196418, y)
|
110
|
+
end
|
111
|
+
|
112
|
+
# This one spawns 25 distinct processes, and notifies each one once,
|
113
|
+
# rather than notifying a single process 25 times.
|
114
|
+
#
|
115
|
+
def test_another_fibonacci
|
116
|
+
x = 1
|
117
|
+
y = 1
|
118
|
+
EM.run {
|
119
|
+
25.times {
|
120
|
+
s = EM.spawn {x,y = y,x+y}
|
121
|
+
s.notify
|
122
|
+
}
|
123
|
+
|
124
|
+
t = EM.spawn {EM.stop}
|
125
|
+
t.notify
|
126
|
+
}
|
127
|
+
assert_equal( 121393, x)
|
128
|
+
assert_equal( 196418, y)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# Make a chain of processes that notify each other in turn
|
133
|
+
# with intermediate fibonacci results. The final process in
|
134
|
+
# the chain stops the loop and returns the result.
|
135
|
+
#
|
136
|
+
def test_fibonacci_chain
|
137
|
+
a,b = nil
|
138
|
+
|
139
|
+
EM.run {
|
140
|
+
nextpid = EM.spawn {|x,y|
|
141
|
+
a,b = x,y
|
142
|
+
EM.stop
|
143
|
+
}
|
144
|
+
|
145
|
+
25.times {
|
146
|
+
n = nextpid
|
147
|
+
nextpid = EM.spawn {|x,y| n.notify( y, x+y )}
|
148
|
+
}
|
149
|
+
|
150
|
+
nextpid.notify( 1, 1 )
|
151
|
+
}
|
152
|
+
|
153
|
+
assert_equal( 121393, a)
|
154
|
+
assert_equal( 196418, b)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
# EM#yield gives a spawed process to yield control to other processes
|
159
|
+
# (in other words, to stop running), and to specify a different code block
|
160
|
+
# that will run on its next notification.
|
161
|
+
#
|
162
|
+
def test_yield
|
163
|
+
a = 0
|
164
|
+
EM.run {
|
165
|
+
n = EM.spawn {
|
166
|
+
a += 10
|
167
|
+
EM.yield {
|
168
|
+
a += 20
|
169
|
+
EM.yield {
|
170
|
+
a += 30
|
171
|
+
EM.stop
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
175
|
+
n.notify
|
176
|
+
n.notify
|
177
|
+
n.notify
|
178
|
+
}
|
179
|
+
assert_equal( 60, a )
|
180
|
+
end
|
181
|
+
|
182
|
+
# EM#yield_and_notify behaves like EM#yield, except that it also notifies the
|
183
|
+
# yielding process. This may sound trivial, since the yield block will run very
|
184
|
+
# shortly after with no action by the program, but this actually can be very useful,
|
185
|
+
# because it causes the reactor core to execute once before the yielding process
|
186
|
+
# gets control back. So it can be used to allow heavily-used network connections
|
187
|
+
# to clear buffers, or allow other processes to process their notifications.
|
188
|
+
#
|
189
|
+
# Notice in this test code that only a simple notify is needed at the bottom
|
190
|
+
# of the initial block. Even so, all of the yielded blocks will execute.
|
191
|
+
#
|
192
|
+
def test_yield_and_notify
|
193
|
+
a = 0
|
194
|
+
EM.run {
|
195
|
+
n = EM.spawn {
|
196
|
+
a += 10
|
197
|
+
EM.yield_and_notify {
|
198
|
+
a += 20
|
199
|
+
EM.yield_and_notify {
|
200
|
+
a += 30
|
201
|
+
EM.stop
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
n.notify
|
206
|
+
}
|
207
|
+
assert_equal( 60, a )
|
208
|
+
end
|
209
|
+
|
210
|
+
# resume is an alias for notify.
|
211
|
+
#
|
212
|
+
def test_resume
|
213
|
+
EM.run {
|
214
|
+
n = EM.spawn {EM.stop}
|
215
|
+
n.resume
|
216
|
+
}
|
217
|
+
assert true
|
218
|
+
end
|
219
|
+
|
220
|
+
# run is an idiomatic alias for notify.
|
221
|
+
#
|
222
|
+
def test_run
|
223
|
+
EM.run {
|
224
|
+
(EM.spawn {EM.stop}).run
|
225
|
+
}
|
226
|
+
assert true
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
# Clones the ping-pong example from the Erlang tutorial, in much less code.
|
231
|
+
# Illustrates that a spawned block executes in the context of a SpawnableObject.
|
232
|
+
# (Meaning, we can pass self as a parameter to another process that can then
|
233
|
+
# notify us.)
|
234
|
+
#
|
235
|
+
def test_ping_pong
|
236
|
+
n_pongs = 0
|
237
|
+
EM.run {
|
238
|
+
pong = EM.spawn {|x, ping|
|
239
|
+
n_pongs += 1
|
240
|
+
ping.notify( x-1 )
|
241
|
+
}
|
242
|
+
ping = EM.spawn {|x|
|
243
|
+
if x > 0
|
244
|
+
pong.notify x, self
|
245
|
+
else
|
246
|
+
EM.stop
|
247
|
+
end
|
248
|
+
}
|
249
|
+
ping.notify 3
|
250
|
+
}
|
251
|
+
assert_equal( 3, n_pongs )
|
252
|
+
end
|
253
|
+
|
254
|
+
# Illustrates that you can call notify inside a notification, and it will cause
|
255
|
+
# the currently-executing process to be re-notified. Of course, the new notification
|
256
|
+
# won't run until sometime after the current one completes.
|
257
|
+
#
|
258
|
+
def test_self_notify
|
259
|
+
n = 0
|
260
|
+
EM.run {
|
261
|
+
pid = EM.spawn {|x|
|
262
|
+
if x > 0
|
263
|
+
n += x
|
264
|
+
notify( x-1 )
|
265
|
+
else
|
266
|
+
EM.stop
|
267
|
+
end
|
268
|
+
}
|
269
|
+
pid.notify 3
|
270
|
+
}
|
271
|
+
assert_equal( 6, n )
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
# Illustrates that the block passed to #spawn executes in the context of a
|
276
|
+
# SpawnedProcess object, NOT in the local context. This can often be deceptive.
|
277
|
+
#
|
278
|
+
class BlockScopeTest
|
279
|
+
attr_reader :var
|
280
|
+
def run
|
281
|
+
# The following line correctly raises a NameError.
|
282
|
+
# The problem is that the programmer expected the spawned block to
|
283
|
+
# execute in the local context, but it doesn't.
|
284
|
+
#
|
285
|
+
# (EM.spawn { do_something }).notify ### NO! BAD!
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
# The following line correctly passes self as a parameter to the
|
290
|
+
# notified process.
|
291
|
+
#
|
292
|
+
(EM.spawn {|obj| obj.do_something }).notify(self)
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
# Here's another way to do it. This works because "myself" is bound
|
297
|
+
# in the local scope, unlike "self," so the spawned block sees it.
|
298
|
+
#
|
299
|
+
myself = self
|
300
|
+
(EM.spawn { myself.do_something }).notify
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
# And we end the loop.
|
305
|
+
# This is a tangential point, but observe that #notify never blocks.
|
306
|
+
# It merely appends a message to the internal queue of a spawned process
|
307
|
+
# and returns. As it turns out, the reactor processes notifications for ALL
|
308
|
+
# spawned processes in the order that #notify is called. So there is a
|
309
|
+
# reasonable expectation that the process which stops the reactor will
|
310
|
+
# execute after the previous ones in this method. HOWEVER, this is NOT
|
311
|
+
# a documented behavior and is subject to change.
|
312
|
+
#
|
313
|
+
(EM.spawn {EM.stop}).notify
|
314
|
+
end
|
315
|
+
def do_something
|
316
|
+
@var ||= 0
|
317
|
+
@var += 100
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_block_scope
|
322
|
+
bs = BlockScopeTest.new
|
323
|
+
EM.run {
|
324
|
+
bs.run
|
325
|
+
}
|
326
|
+
assert_equal( 200, bs.var )
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
|
+
require "eventmachine"
|
6
|
+
|
7
|
+
module EventMachine
|
8
|
+
def self._set_mocks
|
9
|
+
class <<self
|
10
|
+
alias set_tls_parms_old set_tls_parms
|
11
|
+
alias start_tls_old start_tls
|
12
|
+
def set_tls_parms *args; end
|
13
|
+
def start_tls *args; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self._clear_mocks
|
18
|
+
class <<self
|
19
|
+
alias set_tls_parms set_tls_parms_old
|
20
|
+
alias start_tls start_tls_old
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class TestSslArgs < Test::Unit::TestCase
|
27
|
+
def setup
|
28
|
+
EventMachine._set_mocks
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
EventMachine._clear_mocks
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_tls_params_file_doesnt_exist
|
36
|
+
priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
|
37
|
+
[priv_file, cert_file].all? do |f|
|
38
|
+
assert(!File.exists?(f), "Cert file #{f} seems to exist, and should not for the tests")
|
39
|
+
end
|
40
|
+
|
41
|
+
# associate_callback_target is a pain! (build!)
|
42
|
+
conn = EventMachine::Connection.new('foo')
|
43
|
+
|
44
|
+
assert_raises(EventMachine::FileNotFoundException) do
|
45
|
+
conn.start_tls(:private_key_file => priv_file)
|
46
|
+
end
|
47
|
+
assert_raises(EventMachine::FileNotFoundException) do
|
48
|
+
conn.start_tls(:cert_chain_file => cert_file)
|
49
|
+
end
|
50
|
+
assert_raises(EventMachine::FileNotFoundException) do
|
51
|
+
conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_tls_params_file_does_exist
|
56
|
+
priv_file = Tempfile.new('em_test')
|
57
|
+
cert_file = Tempfile.new('em_test')
|
58
|
+
priv_file_path = priv_file.path
|
59
|
+
cert_file_path = cert_file.path
|
60
|
+
conn = EventMachine::Connection.new('foo')
|
61
|
+
params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
|
62
|
+
begin
|
63
|
+
conn.start_tls params
|
64
|
+
rescue Object
|
65
|
+
assert(false, 'should not have raised an exception')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end if EM.ssl?
|
@@ -0,0 +1,50 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestSSLMethods < Test::Unit::TestCase
|
6
|
+
|
7
|
+
module ServerHandler
|
8
|
+
|
9
|
+
def post_init
|
10
|
+
start_tls
|
11
|
+
end
|
12
|
+
|
13
|
+
def ssl_handshake_completed
|
14
|
+
$server_called_back = true
|
15
|
+
$server_cert_value = get_peer_cert
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClientHandler
|
21
|
+
|
22
|
+
def post_init
|
23
|
+
start_tls
|
24
|
+
end
|
25
|
+
|
26
|
+
def ssl_handshake_completed
|
27
|
+
$client_called_back = true
|
28
|
+
$client_cert_value = get_peer_cert
|
29
|
+
EM.stop_event_loop
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ssl_methods
|
35
|
+
$server_called_back, $client_called_back = false, false
|
36
|
+
$server_cert_value, $client_cert_value = nil, nil
|
37
|
+
|
38
|
+
EM.run {
|
39
|
+
EM.start_server("127.0.0.1", 9999, ServerHandler)
|
40
|
+
EM.connect("127.0.0.1", 9999, ClientHandler)
|
41
|
+
}
|
42
|
+
|
43
|
+
assert($server_called_back)
|
44
|
+
assert($client_called_back)
|
45
|
+
|
46
|
+
assert($server_cert_value.is_a?(NilClass))
|
47
|
+
assert($client_cert_value.is_a?(String))
|
48
|
+
end
|
49
|
+
|
50
|
+
end if EM.ssl?
|
@@ -0,0 +1,148 @@
|
|
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'
|
31
|
+
|
32
|
+
|
33
|
+
class TestTimers < Test::Unit::TestCase
|
34
|
+
|
35
|
+
def setup
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_timer_with_block
|
42
|
+
x = false
|
43
|
+
EventMachine.run {
|
44
|
+
EventMachine::Timer.new(0.25) {
|
45
|
+
x = true
|
46
|
+
EventMachine.stop
|
47
|
+
}
|
48
|
+
}
|
49
|
+
assert x
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_timer_with_proc
|
53
|
+
x = false
|
54
|
+
EventMachine.run {
|
55
|
+
EventMachine::Timer.new(0.25, proc {
|
56
|
+
x = true
|
57
|
+
EventMachine.stop
|
58
|
+
})
|
59
|
+
}
|
60
|
+
assert x
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_timer_cancel
|
64
|
+
x = true
|
65
|
+
EventMachine.run {
|
66
|
+
timer = EventMachine::Timer.new(0.25, proc { x = false })
|
67
|
+
timer.cancel
|
68
|
+
EventMachine::Timer.new(0.5, proc {EventMachine.stop})
|
69
|
+
}
|
70
|
+
assert x
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_periodic_timer
|
74
|
+
x = 0
|
75
|
+
EventMachine.run {
|
76
|
+
EventMachine::PeriodicTimer.new(0.1) do
|
77
|
+
x += 1
|
78
|
+
EventMachine.stop if x == 4
|
79
|
+
end
|
80
|
+
}
|
81
|
+
assert( x == 4 )
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_periodic_timer_cancel
|
85
|
+
x = 0
|
86
|
+
EventMachine.run {
|
87
|
+
pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
|
88
|
+
pt.cancel
|
89
|
+
EventMachine::Timer.new(0.5) {EventMachine.stop}
|
90
|
+
}
|
91
|
+
assert( x == 0 )
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_periodic_timer_self_cancel
|
95
|
+
x = 0
|
96
|
+
EventMachine.run {
|
97
|
+
pt = EventMachine::PeriodicTimer.new(0.1) {
|
98
|
+
x += 1
|
99
|
+
if x == 4
|
100
|
+
pt.cancel
|
101
|
+
EventMachine.stop
|
102
|
+
end
|
103
|
+
}
|
104
|
+
}
|
105
|
+
assert( x == 4 )
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# This test is only applicable to compiled versions of the reactor.
|
110
|
+
# Pure ruby and java versions have no built-in limit on the number of outstanding timers.
|
111
|
+
#
|
112
|
+
def test_timer_change_max_outstanding
|
113
|
+
ten_thousand_timers = proc {
|
114
|
+
10000.times {
|
115
|
+
EM.add_timer(5) {}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
EM.run {
|
119
|
+
if EM.library_type == :pure_ruby
|
120
|
+
ten_thousand_timers.call
|
121
|
+
elsif EM.library_type == :java
|
122
|
+
ten_thousand_timers.call
|
123
|
+
else
|
124
|
+
begin
|
125
|
+
assert_raises( RuntimeError ) {
|
126
|
+
ten_thousand_timers.call
|
127
|
+
}
|
128
|
+
rescue Object
|
129
|
+
p $!
|
130
|
+
assert(false, $!.message)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
EM.stop
|
134
|
+
}
|
135
|
+
|
136
|
+
assert(!EM.reactor_running?, 'Reactor running when it should not be.')
|
137
|
+
assert( EM.get_max_timers != 10001 )
|
138
|
+
EM.set_max_timers( 10001 )
|
139
|
+
assert( EM.get_max_timers == 10001 )
|
140
|
+
|
141
|
+
EM.run {
|
142
|
+
ten_thousand_timers.call
|
143
|
+
EM.stop
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
data/tests/test_ud.rb
ADDED
@@ -0,0 +1,43 @@
|
|
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'
|
30
|
+
|
31
|
+
class TestUserDefinedEvents < Test::Unit::TestCase
|
32
|
+
|
33
|
+
def setup
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_a
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
data/tests/testem.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
module EmTestRunner
|
6
|
+
@em_root = File.expand_path(File.dirname(__FILE__) + '/../')
|
7
|
+
@lib_dir = File.join(@em_root, 'lib')
|
8
|
+
@ext_dir = File.join(@em_root, 'ext')
|
9
|
+
@java_dir = File.join(@em_root, 'java')
|
10
|
+
|
11
|
+
def self.run(glob = 'test_*.rb')
|
12
|
+
$:.unshift(@lib_dir)
|
13
|
+
$:.unshift(@ext_dir)
|
14
|
+
$:.unshift(@java_dir)
|
15
|
+
|
16
|
+
case glob
|
17
|
+
when Array
|
18
|
+
files = glob
|
19
|
+
else
|
20
|
+
files = Dir[File.dirname(__FILE__) + '/' + glob]
|
21
|
+
end
|
22
|
+
|
23
|
+
files.each do |tc|
|
24
|
+
require tc
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $0
|
30
|
+
EmTestRunner.run
|
31
|
+
end
|