Sha256: c262084cdae1f5314a157c493070804f82e136b15a59d93514faa696bece1961

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 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 execption
    #
    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.300

        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

2 entries across 2 versions & 1 rubygems

Version Path
rufus-scheduler-1.0.1 test/scheduler_4_test.rb
rufus-scheduler-1.0 test/scheduler_4_test.rb