Class: TestBasic
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestBasic
show all
- Defined in:
- lib/ext/eventmachine-0.12.10/tests/test_basic.rb
Defined Under Namespace
Modules: BrsTestCli, BrsTestSrv, Trivial
Classes: PostInitError, UnbindError
Constant Summary
collapse
- TestHost =
TODO! This is an unfinished edge case. EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers. A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure block in EM::run). But if EM is processing an unbind request, the release_machine call will cause a segmentation fault.
"127.0.0.1"
- TestPort =
9070
Instance Method Summary
collapse
Instance Method Details
#setup ⇒ Object
34
35
36
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 34
def setup
assert(!EM.reactor_running?)
end
|
#teardown ⇒ Object
38
39
40
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 38
def teardown
assert(!EM.reactor_running?)
end
|
#test_bind_connect ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 229
def test_bind_connect
local_ip = UDPSocket.open {|s| s.connect('google.com', 80); s.addr.last }
bind_port = rand(33333)+1025
test = self
EM.run do
EM.start_server(TestHost, TestPort, Module.new do
define_method :post_init do
begin
test.assert_equal bind_port, Socket.unpack_sockaddr_in(get_peername).first
test.assert_equal local_ip, Socket.unpack_sockaddr_in(get_peername).last
ensure
EM.stop_event_loop
end
end
end)
EM.bind_connect local_ip, bind_port, TestHost, TestPort
end
end
|
#test_byte_range_send ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 217
def test_byte_range_send
$received = ''
$sent = (0..255).to_a.pack('C*')
EM::run {
EM::start_server TestHost, TestPort, BrsTestSrv
EM::connect TestHost, TestPort, BrsTestCli
EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
}
assert_equal($sent, $received)
end
|
#test_libtype ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 44
def test_libtype
lt = EventMachine.library_type
em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
if RUBY_PLATFORM == 'java'
unless em_lib == :pure_ruby
assert_equal( :java, lt )
return
end
end
case em_lib
when :pure_ruby
assert_equal( :pure_ruby, lt )
when :extension
assert_equal( :extension, lt )
when :java
assert_equal( :java, lt )
else
if RUBY_PLATFORM == 'java'
assert_equal( :java, lt )
else
assert_equal( :extension, lt )
end
end
end
|
#test_reactor_thread? ⇒ Boolean
250
251
252
253
254
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 250
def test_reactor_thread?
assert !EM.reactor_thread?
EM.run { assert EM.reactor_thread?; EM.stop }
assert !EM.reactor_thread?
end
|
#test_run_block ⇒ Object
EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS the loop automatically. Contrast with EventMachine#run, which keeps running the reactor even after the supplied block completes.
118
119
120
121
122
123
124
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 118
def test_run_block
assert !EM.reactor_running?
a = nil
EM.run_block { a = "Worked" }
assert a
assert !EM.reactor_running?
end
|
#test_schedule_from_thread ⇒ Object
265
266
267
268
269
270
271
272
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 265
def test_schedule_from_thread
x = false
assert !x
EM.run do
Thread.new { EM.schedule { x = true; EM.stop } }.join
end
assert x
end
|
#test_schedule_on_reactor_thread ⇒ Object
256
257
258
259
260
261
262
263
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 256
def test_schedule_on_reactor_thread
x = false
EM.run do
EM.schedule { x = true }
EM.stop
end
assert x
end
|
#test_set_heartbeat_interval ⇒ Object
274
275
276
277
278
279
280
281
282
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 274
def test_set_heartbeat_interval
interval = 0.5
EM.run {
EM.set_heartbeat_interval interval
$interval = EM.get_heartbeat_interval
EM.stop
}
assert_equal(interval, $interval)
end
|
#xxx_test_post_init_error ⇒ Object
This test causes issues, the machine becomes unreleasable after release_machine suffers an exception in event_callback.
#xxx_test_unbind_error ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_basic.rb', line 151
def xxx_test_unbind_error
assert_raises( RuntimeError ) {
EM.run {
EM.start_server TestHost, TestPort
EM.connect TestHost, TestPort, UnbindError
}
}
end
|