Sha256: 93afc2dc0c92373358928fd50655e02c2709b66c7525353ea5138153893b71e3

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

require 'em_test_helper'

class TestThreadedResource < Test::Unit::TestCase
  def object
    @object ||= {}
  end

  def resource
    @resource = EM::ThreadedResource.new do
      object
    end
  end

  def teardown
    resource.shutdown
  end

  def test_dispatch_completion
    EM.run do
      EM.add_timer(3) do
        EM.stop
        fail 'Resource dispatch timed out'
      end
      completion = resource.dispatch do |o|
        o[:foo] = :bar
        :foo
      end
      completion.callback do |result|
        assert_equal :foo, result
        EM.stop
      end
      completion.errback do |error|
        EM.stop
        fail "Unexpected error: #{error.message}"
      end
    end
    assert_equal :bar, object[:foo]
  end

  def test_dispatch_failure
    completion = resource.dispatch do |o|
      raise 'boom'
    end
    completion.errback do |error|
      assert_kind_of RuntimeError, error
      assert_equal 'boom', error.message
    end
  end

  def test_dispatch_threading
    main = Thread.current
    resource.dispatch do |o|
      o[:dispatch_thread] = Thread.current
    end
    assert_not_equal main, object[:dispatch_thread]
  end

  def test_shutdown
    # This test should get improved sometime. The method returning thread is
    # NOT an api that will be maintained.
    assert !resource.shutdown.alive?
  end
end

Version data entries

15 entries across 13 versions & 2 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_threaded_resource.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/eventmachine-1.2.7/tests/test_threaded_resource.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_threaded_resource.rb
eventmachine-1.2.7-java tests/test_threaded_resource.rb
eventmachine-1.2.7-x64-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.7-x86-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.7 tests/test_threaded_resource.rb
eventmachine-1.2.6-x64-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.6-x86-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.6-java tests/test_threaded_resource.rb
eventmachine-1.2.6 tests/test_threaded_resource.rb
eventmachine-1.2.5-x86-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.5-x64-mingw32 tests/test_threaded_resource.rb
eventmachine-1.2.5-java tests/test_threaded_resource.rb
eventmachine-1.2.5 tests/test_threaded_resource.rb