Skip to content

Commit

Permalink
added tests for custom timeout exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
runa committed Oct 22, 2009
1 parent d33acb3 commit d8ca345
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/system_timer_functional_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions test/system_timer_unit_test.rb
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Expand Up @@ -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.