test/scheduler_test.rb in openwferu-0.9.15 vs test/scheduler_test.rb in openwferu-0.9.16
- old
+ new
@@ -124,18 +124,22 @@
#
# phase 0
count = 0
- scheduler.schedule_every("1s") do
+ job_id = scheduler.schedule_every("1s") do
count += 1
end
- sleep(3.5)
+ sleep 3.5
- assert_equal count, 3
+ assert_equal 3, count
+ job = scheduler.get_job job_id
+
+ assert_equal "1s", job.schedule_info
+
#
# phase 1
es = EverySchedulable.new
@@ -232,11 +236,11 @@
job_id = scheduler.schedule_at Time.now.to_s do
var = true
end
- assert var
+ assert_equal var, true
assert_nil job_id
end
#
# Scheduling in the past, with :discard_past set to true.
@@ -286,9 +290,50 @@
assert_equal value, 0
scheduler.stop
end
+
+ #
+ # Testing tags
+ #
+ def test_10
+
+ scheduler = OpenWFE::Scheduler.new
+ scheduler.start
+
+ value = nil
+
+ scheduler.schedule_in "3s", :tags => "fish" do
+ value = "fish"
+ end
+
+ assert_equal scheduler.find_jobs('deer'), []
+ assert_equal scheduler.find_jobs('fish').size, 1
+
+ scheduler.schedule "* * * * *", :tags => "fish" do
+ value = "cron-fish"
+ end
+ scheduler.schedule "* * * * *", :tags => "vegetable" do
+ value = "daikon"
+ end
+
+ assert_equal scheduler.find_jobs('fish').size, 2
+ #puts scheduler.find_jobs('fish')
+
+ scheduler.find_jobs('fish').each do |job|
+ scheduler.unschedule(job.job_id)
+ end
+
+ assert_equal scheduler.find_jobs('fish'), []
+
+ assert_equal scheduler.find_jobs('vegetable').size, 1
+
+ scheduler.find_jobs('vegetable')[0].unschedule
+
+ assert_equal scheduler.find_jobs('vegetable').size, 0
+ end
+
protected
class TestSchedulable
include OpenWFE::Schedulable