Sha256: c717c597a1a2e6665dfd5857ba0069417da44553e365bd895b1a9018b49c4426

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

#
# Testing the 'rufus-scheduler'
#
# John Mettraux at openwfe.org
#
# Tue Jan  8 13:46:17 JST 2008
#

require 'test/unit'
require 'rufus/scheduler'


class Scheduler4Test < Test::Unit::TestCase

  #def setup
  #end

  #def teardown
  #end

  #
  # Checking that a sleep in a schedule won't raise any exception
  #
  def test_0

    s = Rufus::Scheduler.new
    s.start

    $exception = nil

    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

    sleep 10.600

    s.stop

    assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
    assert_nil $exception
  end

  protected

    class Counters

      attr_reader :counters

      def initialize

        @counters = {}
      end

      def inc (counter)

        @counters[counter] ||= 0
        @counters[counter] += 1

        #puts(
        #  "#{counter} _ " +
        #  "#{Time.now.to_f}  #{@counters.inspect} " +
        #  "(#{Thread.current.object_id})")
      end
    end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rufus-scheduler-1.0.10 test/scheduler_4_test.rb
rufus-scheduler-1.0.9 test/scheduler_4_test.rb
rufus-scheduler-1.0.11 test/scheduler_4_test.rb
rufus-scheduler-1.0.8 test/scheduler_4_test.rb