diff --git a/test/system_timer_functional_test.rb b/test/system_timer_functional_test.rb index bdba81c..ce92384 100644 --- a/test/system_timer_functional_test.rb +++ b/test/system_timer_functional_test.rb @@ -50,7 +50,12 @@ SystemTimer.timeout_after(1) {sleep 5} end end - + test "timeout_after raises CustomTimeout if block takes too long" do + assert_raises(CustomTimeout) do + SystemTimer.timeout_after(1,CustomTimeout) {sleep 5} + end + end + test "timeout_after does not raises Timeout Error if block completes in time" do SystemTimer.timeout_after(5) {sleep 1} end @@ -257,4 +262,4 @@ def assert_timeout_within(expected_timeout_in_seconds, "Timed out after #{elapsed} seconds, expected #{expected_timeout_in_seconds}" end -end \ No newline at end of file +end diff --git a/test/system_timer_unit_test.rb b/test/system_timer_unit_test.rb index 1360eb7..c371e41 100644 --- a/test/system_timer_unit_test.rb +++ b/test/system_timer_unit_test.rb @@ -13,6 +13,17 @@ SystemTimer.timeout_after(5) {} end + test "timeout_after registers a new timer with a custom timeout exception in the timer pool" do + pool = stub_everything + Thread.stubs(:current).returns(:the_current_thread) + SystemTimer.stubs(:timer_pool).returns(pool) + SystemTimer.stubs(:install_next_timer) + SystemTimer.stubs(:restore_original_configuration) + + pool.expects(:add_timer).with(5,CustomTimeout).returns(stub_everything) + SystemTimer.timeout_after(5,CustomTimeout) {} + end + test "timeout_after installs a system timer saving the previous " + "configuration when there is only one timer" do diff --git a/test/test_helper.rb b/test/test_helper.rb index ed09991..3739f30 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,3 +8,5 @@ require 'stringio' require "open-uri" require 'system_timer' +class CustomTimeout < Exception +end