test/scheduler_test.rb in openwferu-0.9.5 vs test/scheduler_test.rb in openwferu-0.9.6
- old
+ new
@@ -104,16 +104,87 @@
#puts text
assert text == "onetwo"
end
+
+ #
+ # test Scheduler::is_cron_string(s)
+ #
+ def test_scheduler_3
+
+ assert OpenWFE::Scheduler.is_cron_string("* * * * *")
+ assert OpenWFE::Scheduler.is_cron_string("10/2 * * * *")
+ assert (not OpenWFE::Scheduler.is_cron_string("10d10m"))
+ end
+
+
+ #
+ # Testing schedule_every()
+ #
+ def test_scheduler_4
+
+ scheduler = OpenWFE::Scheduler.new()
+ scheduler.sstart
+
+ #
+ # phase 0
+
+ count = 0
+
+ scheduler.schedule_every("1s") do
+ count += 1
+ end
+
+ sleep(3.5)
+
+ assert_equal count, 3
+
+ #
+ # phase 1
+
+ es = EverySchedulable.new
+
+ scheduler.schedule_every("500", es, nil)
+
+ sleep(3.2)
+
+ assert_equal es.count, 6
+
+ scheduler.unschedule(es.job_id)
+
+ sleep(1)
+
+ assert_equal es.count, 6
+
+ # done
+
+ scheduler.sstop
+ end
+
protected
class TestSchedulable
include OpenWFE::Schedulable
def trigger (params)
$var = "ok"
+ end
+ end
+
+ class EverySchedulable
+ include OpenWFE::Schedulable
+
+ attr_accessor :job_id, :count
+
+ def initialize
+ @job_id = -1
+ @count = 0
+ end
+
+ def trigger (params)
+ #puts "toto"
+ @count += 1
end
end
end