spec/scheduler_spec.rb in rufus-scheduler-3.0.6 vs spec/scheduler_spec.rb in rufus-scheduler-3.0.7
- old
+ new
@@ -21,13 +21,18 @@
}
t[:rufus_scheduler].should == scheduler
end
- it 'sets a :rufus_scheduler thread local var' do
+ it 'sets :name and :rufus_scheduler in the scheduler thread local vars' do
scheduler = Rufus::Scheduler.new
+
+ scheduler.thread[:name].should ==
+ "rufus_scheduler_#{scheduler.object_id}_scheduler"
+ scheduler.thread[:rufus_scheduler].should ==
+ scheduler
end
it 'accepts a :frequency => integer option' do
scheduler = Rufus::Scheduler.new(:frequency => 2)
@@ -539,9 +544,79 @@
%w[ 0.1s ]
@scheduler.running_jobs(:tag => 't1').map(&:original).should ==
%w[ 0.2s ]
@scheduler.running_jobs(:tags => %w[ t0 t1 ]).map(&:original).should ==
[]
+ end
+ end
+
+ describe '#occurrences(time0, time1)' do
+
+ it 'returns a { job => [ times ] } of job occurrences' do
+
+ j0 = @scheduler.schedule_in '7m' do; end
+ j1 = @scheduler.schedule_at '10m' do; end
+ j2 = @scheduler.schedule_every '5m' do; end
+ j3 = @scheduler.schedule_interval '5m' do; end
+ j4 = @scheduler.schedule_cron '* * * * *' do; end
+
+ h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 11 * 60)
+
+ h.size.should == 5
+ h[j0].should == [ j0.next_time ]
+ h[j1].should == [ j1.next_time ]
+ h[j2].size.should == 2
+ h[j3].size.should == 2
+ h[j4].size.should == 7
+ end
+
+ it 'returns a [ [ time, job ], ... ] of job occurrences when :timeline' do
+
+ j0 = @scheduler.schedule_in '5m' do; end
+ j1 = @scheduler.schedule_in '10m' do; end
+
+ a =
+ @scheduler.occurrences(Time.now + 4 * 60, Time.now + 11 * 60, :timeline)
+
+ a[0][0].should be_within_1s_of(Time.now + 5 * 60)
+ a[0][1].should == j0
+ a[1][0].should be_within_1s_of(Time.now + 10 * 60)
+ a[1][1].should == j1
+ end
+
+ it 'respects :first_at for repeat jobs' do
+
+ j0 = @scheduler.schedule_every '5m', :first_in => '10m' do; end
+
+ h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 16 * 60)
+
+ h[j0][0].should be_within_1s_of(Time.now + 10 * 60)
+ h[j0][1].should be_within_1s_of(Time.now + 15 * 60)
+ end
+
+ it 'respects :times for repeat jobs' do
+
+ j0 = @scheduler.schedule_every '1m', :times => 10 do; end
+
+ h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 16 * 60)
+
+ h[j0].size.should == 6
+ end
+ end
+
+ describe '#timeline(time0, time1)' do
+
+ it 'returns a [ [ time, job ], ... ] of job occurrences' do
+
+ j0 = @scheduler.schedule_in '5m' do; end
+ j1 = @scheduler.schedule_in '10m' do; end
+
+ a = @scheduler.timeline(Time.now + 4 * 60, Time.now + 11 * 60)
+
+ a[0][0].should be_within_1s_of(Time.now + 5 * 60)
+ a[0][1].should == j0
+ a[1][0].should be_within_1s_of(Time.now + 10 * 60)
+ a[1][1].should == j1
end
end
#--
# management methods