Sha256: 19d7887d4e4a0a3e87dd4feaead0176df387536bbca9df9f99ffb8460b0990f5
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
require_relative 'em_test_helper' class TestDefer < Test::Unit::TestCase def test_defers n = 0 n_times = 20 EM.run { n_times.times { work_proc = proc { n += 1 } callback = proc { EM.stop if n == n_times } EM.defer work_proc, callback } } assert_equal( n, n_times ) end def test_errbacks iterations = 20 callback_parameter = rand(100) callback_parameters = [] callback_op = proc { callback_parameter } callback = proc { |result| callback_parameters << result } errback_parameter = Exception.new errback_parameters = [] errback_op = proc { raise errback_parameter } errback = proc { |error| errback_parameters << error } EventMachine.run do (1..iterations).each { |index| EventMachine.defer(index.even? ? callback_op : errback_op, callback, errback) } EventMachine.add_periodic_timer(0.1) { EventMachine.stop if EventMachine.defers_finished? } end assert_equal(callback_parameters.select { |parameter| parameter == callback_parameter }.length, iterations * 0.5) assert_equal(errback_parameters.select{ |parameter| parameter == errback_parameter }.length, iterations * 0.5) end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
eventmachine-mkroman-1.3.0.dev.1 | tests/test_defer.rb |
wj_eventmachine-1.3.2 | tests/test_defer.rb |
wj_eventmachine-1.3.1 | tests/test_defer.rb |
wj_eventmachine-1.3.0.dev.1 | tests/test_defer.rb |