Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added tests for custom timeout exceptions

  • Loading branch information...
commit 7a6922999ae436d17ec4d1d63a4b470782a4386b 1 parent c529a26
runa authored ph7 committed
View
9 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
+end
View
11 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
View
2  test/test_helper.rb
@@ -8,3 +8,5 @@
require 'stringio'
require "open-uri"
require 'system_timer'
+class CustomTimeout < Exception
+end
Please sign in to comment.
Something went wrong with that request. Please try again.