Sha256: 3ecefd7b94121fb189a5f795b5b2ea56afcbb9bf1407ea5425b176f635071d55

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

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

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

#
# testing otime and the scheduler
#

class Scheduler2Test < Test::Unit::TestCase

  #def setup
  #end

  #def teardown
  #end

  def test_0

    scheduler = OpenWFE::Scheduler.new
    scheduler.sstart

    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 = OpenWFE::Scheduler.new
    scheduler.sstart

    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 = OpenWFE::Scheduler.new
    scheduler.sstart

    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 = OpenWFE::Scheduler.new
    scheduler.sstart

    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.6 test/scheduler_2_test.rb