spec/job_cron_spec.rb in rufus-scheduler-3.0.3 vs spec/job_cron_spec.rb in rufus-scheduler-3.0.4

- old
+ new

@@ -60,8 +60,47 @@ #p [ job.first_at, job.first_at.to_f ] job.first_at.should be_within_1s_of(t + 3) job.last_time.should == nil end + + it 'triggers for the first time at first_at' do + + first_time = nil + t = Time.now + + job = @scheduler.schedule_cron '* * * * * *', :first_in => '3s' do + first_time ||= Time.now + end + sleep 4.5 + + job.first_at.should be_within_1s_of(t + 3) + first_time.should be_within_1s_of(job.first_at) + end + end + + context 'scheduling the cron itself' do + + # for https://github.com/jmettraux/rufus-scheduler/issues/95 + # + # schedule_cron takes more than 30 seconds, blocking... + # + it 'does not sit scheduling and blocking...' do + + n = Time.now + first = nil + + job = @scheduler.schedule_cron '*/2 * * * * *' do + first ||= Time.now + end + + (Time.now - n).should < 1.0 + + loop do + next unless first + (first - n).should < 4.0 + break + end + end end end