test/scheduler_4_test.rb in rufus-scheduler-1.0.5 vs test/scheduler_4_test.rb in rufus-scheduler-1.0.6
- old
+ new
@@ -11,71 +11,71 @@
require 'rufus/scheduler'
class Scheduler4Test < Test::Unit::TestCase
- #def setup
- #end
+ #def setup
+ #end
- #def teardown
- #end
+ #def teardown
+ #end
- #
- # Checking that a sleep in a schedule won't raise any exception
- #
- def test_0
+ #
+ # Checking that a sleep in a schedule won't raise any exception
+ #
+ def test_0
- s = Rufus::Scheduler.new
- s.start
+ s = Rufus::Scheduler.new
+ s.start
- $exception = nil
+ $exception = nil
- class << s
- def lwarn (&block)
- $exception = block.call
- end
- end
+ class << s
+ def lwarn (&block)
+ $exception = block.call
+ end
+ end
- counters = Counters.new
-
- s.schedule_every "2s" do
- counters.inc :a
- sleep 4
- counters.inc :b
- end
- s.schedule_every "3s" do
- counters.inc :c
- end
- #p Time.now.to_f
+ counters = Counters.new
- sleep 10.300
+ s.schedule_every "2s" do
+ counters.inc :a
+ sleep 4
+ counters.inc :b
+ end
+ s.schedule_every "3s" do
+ counters.inc :c
+ end
+ #p Time.now.to_f
- s.stop
+ sleep 10.300
- assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
- assert_nil $exception
- end
+ s.stop
- protected
+ assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
+ assert_nil $exception
+ end
- class Counters
+ protected
- attr_reader :counters
+ class Counters
- def initialize
+ attr_reader :counters
- @counters = {}
- end
+ def initialize
- def inc (counter)
+ @counters = {}
+ end
- @counters[counter] ||= 0
- @counters[counter] += 1
+ def inc (counter)
- #puts(
- # "#{counter} _ " +
- # "#{Time.now.to_f} #{@counters.inspect} " +
- # "(#{Thread.current.object_id})")
- end
- end
+ @counters[counter] ||= 0
+ @counters[counter] += 1
+
+ #puts(
+ # "#{counter} _ " +
+ # "#{Time.now.to_f} #{@counters.inspect} " +
+ # "(#{Thread.current.object_id})")
+ end
+ end
end