Sha256: 4c6b592185804ecb0bdca9b9473c4ba245d62b2b3d525faf16447b2712ecd902

Contents?: true

Size: 1.17 KB

Versions: 40

Compression:

Stored size: 1.17 KB

Contents

require '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

40 entries across 37 versions & 4 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/eventmachine-1.2.7/tests/test_defer.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/eventmachine-1.2.7/tests/test_defer.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_defer.rb
eventmachine-1.2.7-java tests/test_defer.rb
eventmachine-1.2.7-x64-mingw32 tests/test_defer.rb
eventmachine-1.2.7-x86-mingw32 tests/test_defer.rb
eventmachine-1.2.7 tests/test_defer.rb
eventmachine-1.2.6-x64-mingw32 tests/test_defer.rb
eventmachine-1.2.6-x86-mingw32 tests/test_defer.rb
eventmachine-1.2.6-java tests/test_defer.rb
eventmachine-1.2.6 tests/test_defer.rb
eventmachine-1.2.5-x86-mingw32 tests/test_defer.rb
eventmachine-1.2.5-x64-mingw32 tests/test_defer.rb
eventmachine-1.2.5-java tests/test_defer.rb
eventmachine-1.2.5 tests/test_defer.rb
eventmachine-1.2.3-x64-mingw32 tests/test_defer.rb
eventmachine-1.2.3-x86-mingw32 tests/test_defer.rb
eventmachine-1.2.3-java tests/test_defer.rb
eventmachine-1.2.3 tests/test_defer.rb
eventmachine-1.2.2-java tests/test_defer.rb