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, :watch => w))
19 assert_equal 1, @t.events.size
22 def test_timer_should_remove_expired_events
23 @t.schedule(stub(:interval => -1, :watch => Watch.new))
25 assert_equal 0, @t.events.size
28 def test_timer_should_remove_only_expired_events
30 @t.schedule(stub(:interval => -1, :watch => w))
31 @t.schedule(stub(:interval => 1000, :watch => w))
33 assert_equal 1, @t.events.size
36 def test_timer_should_sort_timer_events
38 @t.schedule(stub(:interval => 1000, :watch => w))
39 @t.schedule(stub(:interval => 800, :watch => w))
40 @t.schedule(stub(:interval => 900, :watch => w))
41 @t.schedule(stub(:interval => 100, :watch => w))
43 assert_equal [100, 800, 900, 1000], @t.events.map { |x| x.condition.interval }
46 def test_unschedule_should_remove_conditions
52 assert_equal 2, @t.events.size
54 assert_equal 1, @t.events.size
57 def test_time_should_recover_from_exceptions
59 @t.expects(:trigger).raises(Exception.new)
61 @t.schedule(stub(:interval => -1, :watch => w))
63 @t.schedule(stub(:interval => 0, :watch => w))
69 def test_join_should_join
70 Thread.any_instance.expects(:join)