Permalink
Browse files

added tests for custom timeout exceptions

  • Loading branch information...
1 parent d33acb3 commit d8ca3452e462ea909d8e11a6091e7c30dfa3a1a8 runa committed Oct 22, 2009
Showing with 20 additions and 2 deletions.
  1. +7 −2 test/system_timer_functional_test.rb
  2. +11 −0 test/system_timer_unit_test.rb
  3. +2 −0 test/test_helper.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
+end
@@ -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
View
@@ -8,3 +8,5 @@
require 'stringio'
require "open-uri"
require 'system_timer'
+class CustomTimeout < Exception
+end

0 comments on commit d8ca345

Please sign in to comment.