1 require File.dirname(__FILE__) + '/helper'
3 class TestTimer < Test::Unit::TestCase
9 def test_new_timer_should_have_no_events
10 assert_equal 0, @t.events.size
13 def test_schedule_should_queue_event
14 Time.stubs(:now).returns(0)
17 @t.schedule(stub(:interval => 20))
19 assert_equal 1, @t.events.size
22 def test_timer_should_remove_expired_events
23 @t.schedule(stub(:interval => 0))
25 assert_equal 0, @t.events.size
28 def test_timer_should_remove_only_expired_events
29 @t.schedule(stub(:interval => 0))
30 @t.schedule(stub(:interval => 1000))
32 assert_equal 1, @t.events.size
35 def test_timer_should_sort_timer_events
36 @t.schedule(stub(:interval => 1000))
37 @t.schedule(stub(:interval => 800))
38 @t.schedule(stub(:interval => 900))
39 @t.schedule(stub(:interval => 100))
41 assert_equal [100, 800, 900, 1000], @t.events.map { |x| x.condition.interval }
44 def test_unschedule_should_remove_conditions
49 assert_equal 2, @t.events.size
51 assert_equal 1, @t.events.size
54 def test_time_should_recover_from_exceptions
55 @t.expects(:trigger).raises(Exception.new)
57 @t.schedule(stub(:interval => 0))
59 @t.schedule(stub(:interval => 0))
65 def test_join_should_join
66 Thread.any_instance.expects(:join)