Created
April 23, 2014 00:57
-
-
Save futhr/11199519 to your computer and use it in GitHub Desktop.
Test sidetiq -- coderwall.com/p/nqpa-w
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HardWorker | |
include Sidekiq::Worker | |
include Sidetiq::Schedulable | |
recurrence { hourly } | |
def perform | |
# Do some work | |
end | |
end | |
describe HardWorker do | |
describe 'scheduling' do | |
it 'will be scheduled hourly' do | |
valid, invalid = times | |
expect(next_occurrence).to eq valid | |
expect(next_occurrence).not_to eq invalid | |
Timecop.freeze(Time.zone.now + 1.hour) | |
# Testing the past time is no longer valid | |
expect(next_occurrence).not_to eq valid | |
valid, invalid = times(2.hours) | |
expect(next_occurrence).to eq valid | |
expect(next_occurrence).not_to eq invalid | |
end | |
end | |
private | |
def next_occurrence | |
HardWorker.schedule.next_occurrence | |
end | |
def times(offset = 1.hour) | |
valid = Time.zone.now.beginning_of_hour + 1.hour | |
invalid = valid + 1.minute | |
[valid, invalid] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment