Sha256: 6af1cc350fd7ab7ff9427d5fa2bc03a5c512f0ba5a0200753851e63e8483504f

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

#
# Testing Rufus
#
# John Mettraux at openwfe.org
#
# Sun Oct 29 16:18:25 JST 2006
#

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

require 'test/unit'
require 'openwfe/util/scheduler'


#
# testing otime and the scheduler
#
class Scheduler2Test < Test::Unit::TestCase

  def test_0

    scheduler = Rufus::Scheduler.new
    scheduler.start

    counter = 0
    $error_counter = 0

    def scheduler.lwarn (&block)
      #puts block.call
      $error_counter += 1
    end

    job_id = scheduler.schedule_every "500" do
      counter += 1
      raise "exception!"
    end

    sleep 2.300

    scheduler.sstop

    assert_equal 4, counter, "execution count wrong"
    assert_equal 4, $error_counter, "error count wrong"
  end

  def test_1

    # repeating myself

    scheduler = Rufus::Scheduler.new
    scheduler.start

    counter = 0
    $error_counter = 0

    def scheduler.lwarn (&block)
      #puts block.call
      $error_counter += 1
    end

    job_id = scheduler.schedule_every "500", :try_again => false do
      counter += 1
      raise "exception?"
    end

    sleep 2.300

    scheduler.sstop

    assert_equal 1, counter, "execution count wrong"
    assert_equal 1, $error_counter, "error count wrong"
  end

  def test_2

    scheduler = Rufus::Scheduler.new
    scheduler.start

    def scheduler.lwarn (&block)
      puts block.call
    end

    counter = 0

    job_id = scheduler.schedule_every "500" do |job_id, at, params|
      counter += 1
      params[:dont_reschedule] = true if counter == 2
    end

    sleep 3.000

    assert_equal 2, counter
  end

  def test_3

    # repeating myself ...

    scheduler = Rufus::Scheduler.new
    scheduler.start

    def scheduler.lwarn (&block)
      puts block.call
    end

    counter = 0

    job_id = scheduler.schedule_every "500" do |job_id, at, params|
      counter += 1
      params[:every] = "1s" if counter == 2
    end

    sleep 5.000

    assert_equal 2 + 3, counter
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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