Skip to content

Instantly share code, notes, and snippets.

@futhr
Created April 23, 2014 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futhr/11199519 to your computer and use it in GitHub Desktop.
Save futhr/11199519 to your computer and use it in GitHub Desktop.
Test sidetiq -- coderwall.com/p/nqpa-w
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