Sha256: 1359772c3bedffb6879472ae19019224c6b5fbecfac03cc25cfd0e24d88177f7

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

require File.dirname(__FILE__) + '/helper'

class TestTimer < Test::Unit::TestCase
  def setup
    Timer.reset
    @t = Timer.get
  end
  
  def test_new_timer_should_have_no_events
    assert_equal 0, @t.events.size
  end
  
  def test_schedule_should_queue_event
    Time.stubs(:now).returns(0)
    
    w = Watch.new
    @t.schedule(stub(:interval => 20))
    
    assert_equal 1, @t.events.size
  end
  
  def test_timer_should_remove_expired_events
    @t.schedule(stub(:interval => 0))
    sleep(0.3)
    assert_equal 0, @t.events.size
  end
  
  def test_timer_should_remove_only_expired_events
    @t.schedule(stub(:interval => 0))
    @t.schedule(stub(:interval => 1000))
    sleep(0.3)
    assert_equal 1, @t.events.size
  end
  
  def test_timer_should_sort_timer_events
    @t.schedule(stub(:interval => 1000))
    @t.schedule(stub(:interval => 800))
    @t.schedule(stub(:interval => 900))
    @t.schedule(stub(:interval => 100))
    sleep(0.3)
    assert_equal [100, 800, 900, 1000], @t.events.map { |x| x.condition.interval }
  end
  
  def test_unschedule_should_remove_conditions
    a = stub()
    b = stub()
    @t.schedule(a, 100)
    @t.schedule(b, 200)
    assert_equal 2, @t.events.size
    @t.unschedule(a)
    assert_equal 1, @t.events.size
  end
  
  # join
  
  def test_join_should_join
    Thread.any_instance.expects(:join)
    @t.join
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
god-0.3.0 test/test_timer.rb
god-0.4.0 test/test_timer.rb
god-0.4.1 test/test_timer.rb
god-0.4.3 test/test_timer.rb
god-0.5.0 test/test_timer.rb