Sha256: a8f645342228e39feb482089e6056b5a9798ee2d908f7cdb62c812d116835716

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

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

require 'test/unit'

require 'openwfe/util/otime'
require 'openwfe/util/scheduler'


#
# testing otime and the scheduler (its cron aspect)
#
class CronTest < Test::Unit::TestCase

    #def setup
    #end

    #def teardown
    #end

    def test_0

        $var = 0

        scheduler = OpenWFE::Scheduler.new
        scheduler.start

        sid = scheduler.schedule(
            '* * * * *',
            :schedulable => CounterSchedulable.new)

        assert sid, "scheduler did not return a job id"

        sleep 120
        scheduler.stop

        #puts ">#{$var}<"

        assert_equal $var, 2, "$var should be at 2, it's at #{$var}"
    end

    def test_1

        scheduler = OpenWFE::Scheduler.new
        scheduler.start

        sec = nil
        has_gone_wrong = false
        counter = 0

        scheduler.schedule "* * * * * *" do
            t = Time.new
            if (t.sec == sec)
                has_gone_wrong = true
                #print "x"
            else
                #print "."
            end
            #STDOUT.flush
            sec = t.sec
            counter = counter + 1
        end

        sleep 10
        scheduler.stop

        assert_equal 10, counter
        assert (not has_gone_wrong)
    end

    def test_2

        scheduler = OpenWFE::Scheduler.new
        scheduler.start

        seen = false
        has_gone_wrong = false

        scheduler.schedule "7 * * * * *" do
            if seen
                has_gone_wrong = true
                #print "x"
            else
                seen = true
                #print "."
            end
            #STDOUT.flush
        end

        sleep 61
        scheduler.stop

        assert seen
        assert (not has_gone_wrong)
    end

    protected

        class CounterSchedulable
            include OpenWFE::Schedulable

            def trigger (params)
                $var = $var + 1
            end
        end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openwferu-0.9.16 test/cron_test.rb