test/scheduler_test.rb in openwferu-0.9.12 vs test/scheduler_test.rb in openwferu-0.9.12.863

- old
+ new

@@ -138,13 +138,13 @@ # phase 1 es = EverySchedulable.new job_id = scheduler.schedule_every("500", es) - #job_id = scheduler.schedule_every("500", :schedulable => es) - sleep(3.4) + #sleep(3.4) # was a bit soonish for JRuby... + sleep 3.5 assert_equal es.count, 6 scheduler.unschedule(job_id) @@ -200,9 +200,92 @@ assert_equal value, 1 sleep 4 assert_equal value, 1 + + scheduler.stop + end + + # + # Testing custom precision. + # + def test_scheduler_7 + + scheduler = OpenWFE::Scheduler.new(:scheduler_precision => 0.100) + + assert_equal scheduler.precision, 0.100 + end + + # + # Making sure that a job scheduled in the past is executed immediately + # and not scheduled. + # + # This test also makes sure that schedule_at() understands the + # time.to_s format. + # + def test_8 + + scheduler = OpenWFE::Scheduler.new + scheduler.start + + var = false + + job_id = scheduler.schedule_at Time.now.to_s do + var = true + end + + assert var + assert_nil job_id + end + + # + # Scheduling in the past, with :discard_past set to true. + # + def test_8b + + scheduler = OpenWFE::Scheduler.new + scheduler.start + + var = nil + + job_id = scheduler.schedule_at(Time.now.to_s, :discard_past => true) do + var = "something" + end + + assert_nil var + assert_nil job_id + + scheduler.stop + end + + # + # Testing restarting the scheduler. + # + def test_9 + + scheduler = OpenWFE::Scheduler.new + scheduler.start + + value = nil + + scheduler.schedule_in "2s" do + value = 0 + end + + assert_nil value + + scheduler.stop + + sleep 0.5 + + scheduler.start + + assert_nil value + + sleep 2 + + assert_equal value, 0 scheduler.stop end protected