# # Testing OpenWFE # # John Mettraux at openwfe.org # # Sun Oct 29 16:18:25 JST 2006 # require 'test/unit' #require 'openwfe/otime' require 'openwfe/util/scheduler' # # testing otime and the scheduler # class SchedulerTest < Test::Unit::TestCase #def setup #end #def teardown #end def test_scheduler_0 $var = nil scheduler = OpenWFE::Scheduler.new() scheduler.start sid = scheduler.schedule_in('2s', TestSchedulable.new, nil) assert \ sid, "scheduler_0 did not return a job id" assert \ (not $var), "scheduler_0 is blocking but should not" sleep(2.5) scheduler.do_stop #puts ">#{$var}<" assert \ ($var == "ok"), "scheduler_0 didn't work" end def test_scheduler_1 $var = nil scheduler = OpenWFE::Scheduler.new() scheduler.start sid = scheduler.schedule_in('1s') do $var = "ok..1" end assert \ sid, "scheduler_1 did not return a job id" assert \ (not $var), "scheduler_1 is blocking but should not" sleep(2) scheduler.do_stop #puts ">#{$var}<" assert \ ($var == "ok..1"), "scheduler_1 didn't work" end protected class TestSchedulable include OpenWFE::Schedulable def trigger (params) $var = "ok" end end end