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
15 @t.schedule(stub(:interval => 20, :watch => w))
17 assert_equal 1, @t.events.size
20 def test_timer_should_remove_expired_events
21 @t.schedule(stub(:interval => -1, :watch => Watch.new))
23 assert_equal 0, @t.events.size
26 def test_timer_should_remove_only_expired_events
28 @t.schedule(stub(:interval => -1, :watch => w))
29 @t.schedule(stub(:interval => 1000, :watch => w))
31 assert_equal 1, @t.events.size
34 def test_timer_should_sort_timer_events
36 @t.schedule(stub(:interval => 1000, :watch => w))
37 @t.schedule(stub(:interval => 800, :watch => w))
38 @t.schedule(stub(:interval => 900, :watch => w))
39 @t.schedule(stub(:interval => 100, :watch => w))
41 assert_equal [100, 800, 900, 1000], @t.events.map { |x| x.condition.interval }
44 def test_unschedule_should_remove_conditions
50 assert_equal 2, @t.conditions.size
52 assert_equal 1, @t.conditions.size
55 def test_time_should_recover_from_exceptions
57 @t.expects(:trigger).raises(Exception.new)
59 @t.schedule(stub(:interval => -1, :watch => w))
61 @t.schedule(stub(:interval => 0, :watch => w))
67 def test_join_should_join
68 Thread.any_instance.expects(:join)