Sha256: ba49b1a291bbe42f0f24f9e33a4b9c6061c395e201f18ee6c2e664b0929dd2e8
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 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 (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 2, $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 [ 9, 10 ].include?(counter), "not 9 or 10 but #{counter}" assert (not has_gone_wrong) end def test_2 scheduler = OpenWFE::Scheduler.new scheduler.start counter = 0 scheduler.schedule "7 * * * * *" do counter += 1 end sleep 61 scheduler.stop assert_equal 1, counter # baby just one ... time end # # testing cron unschedule # def test_3 scheduler = OpenWFE::Scheduler.new scheduler.start counter = 0 job_id = scheduler.schedule "* * * * *" do counter += 1 end sleep 0.300 #puts "job_id : #{job_id}" assert_equal 1, scheduler.cron_job_count scheduler.unschedule job_id sleep 0.300 assert_equal 0, scheduler.cron_job_count scheduler.stop 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 |
---|---|
rufus-scheduler-1.0.6 | test/cron_test.rb |