Sha256: 3d214505a6cbf3ace370a7cb59d9491e06976c89fe4005231856b0cf14ca1da6

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

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

$:.unshift(File.dirname(__FILE__) + '/../lib')

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


class Scheduler4Test < Test::Unit::TestCase

  #
  # 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

1 entries across 1 versions & 1 rubygems

Version Path
rufus-scheduler-1.0.12 test/scheduler_4_test.rb