# # Testing OpenWFEru # # John Mettraux at openwfe.org # # Sun Oct 29 16:18:25 JST 2006 # require 'test/unit' require 'otime' require 'ru/scheduler' # # testing otime and the scheduler # class TimeTest < Test::Unit::TestCase #def setup #end #def teardown #end def test_is_digit for i in 0...9 si = "#{i}" assert \ OpenWFE::is_digit?(si), "'#{si}' should be a digit" end assert \ (not OpenWFE::is_digit?(1)), "the integer 1 is not a character digit" assert \ (not OpenWFE::is_digit?("a")), "the character 'a' is not a character digit" end def test_parse_time_string pts("1000", 1.0) pts("1h", 3600.0) pts("1h10s", 3610.0) end def test_scheduler_0 $var = nil scheduler = OpenWFEru::Scheduler.new() scheduler.start scheduler.schedule_in('2s', TestSchedulable.new, nil) sleep(2.5) scheduler.stop #puts ">#{$var}<" assert \ ($var == "ok"), "scheduler_0 didn't work" end def test_cron_0 $var = 0 scheduler = OpenWFEru::Scheduler.new() scheduler.start scheduler.schedule('* * * * *', CounterSchedulable.new, nil) sleep(120) scheduler.stop #puts ">#{$var}<" assert \ ($var == 2), "cron_0 failed, $var is #{$var}" end protected class TestSchedulable include OpenWFEru::Schedulable def trigger (params) $var = "ok" end end class CounterSchedulable include OpenWFEru::Schedulable def trigger (params) $var = $var + 1 end end def pts (time_string, seconds) assert \ (OpenWFE::parse_time_string(time_string) == seconds), "'#{time_string}' did not map to #{seconds} seconds" end end