Sha256: 40a96ebc73ab0789bedc739896d208b689efaa9057d1ac2bc4be64da90c8edb5

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path(__FILE__ + '/../../test_helper')

unit_tests do

  test "thread aware dispatcher returns original dispath result" do
    dispatcher = Class.new
    dispatcher.expects(:dispatch).with(:the_args).returns(:the_result)
    dispatcher.send :include, XRay::ThreadAwareDispatcher
    dispatcher.dispatch(:the_args)
  end

  test "thread aware dispatcher adds accessor for thread in dispatch" do
    dispatcher = Class.new
    dispatcher.stubs(:dispatch)
    dispatcher.send :include, XRay::ThreadAwareDispatcher
    dispatcher.thread_in_dispatch
  end

  test "thread in dispatch is nil when not in dispatch" do
    dispatcher = Class.new
    dispatcher.stubs(:dispatch)
    dispatcher.send :include, XRay::ThreadAwareDispatcher
    assert_nil dispatcher.thread_in_dispatch
  end

  test "thread in dispatch is nil when dispatch raises" do
    begin
      dispatcher = Class.new
      dispatcher.expects(:dispatch).raises(StandardError.new("Fake Problem"))
      dispatcher.send :include, XRay::ThreadAwareDispatcher
      dispatcher.dispatch
      flunk "Should relay exception"
    rescue StandardError
      assert_nil dispatcher.thread_in_dispatch
    end
  end

  test "thread in dispatch is set to current thread when in dispatch" do
    dispatcher = Class.new do
      extend Test::Unit::Assertions

      def self.dispatch(*args)
        assert_equal Thread.current, thread_in_dispatch 
      end

      include XRay::ThreadAwareDispatcher
    end
    dispatcher.dispatch
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
XRay-1.0 test/unit/thread_aware_dispatcher_test.rb
XRay-1.0.1 test/unit/thread_aware_dispatcher_test.rb
XRay-1.0.3 test/unit/thread_aware_dispatcher_test.rb