2012-05-25 23:21:42 -04:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq/scheduled'
|
|
|
|
|
|
|
|
class TestScheduling < MiniTest::Unit::TestCase
|
|
|
|
describe 'middleware' do
|
|
|
|
before do
|
|
|
|
@redis = MiniTest::Mock.new
|
|
|
|
# Ugh, this is terrible.
|
|
|
|
Sidekiq.instance_variable_set(:@redis, @redis)
|
|
|
|
|
|
|
|
def @redis.with; yield self; end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ScheduledWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
def perform(x)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules a job via interval' do
|
2012-06-20 18:24:23 -04:00
|
|
|
@redis.expect :zadd, true, ['schedule', String, String]
|
2012-08-11 14:47:25 -04:00
|
|
|
assert ScheduledWorker.perform_in(600, 'mike')
|
2012-05-25 23:21:42 -04:00
|
|
|
@redis.verify
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules a job via timestamp' do
|
2012-06-20 18:24:23 -04:00
|
|
|
@redis.expect :zadd, true, ['schedule', String, String]
|
2012-08-11 14:47:25 -04:00
|
|
|
assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
|
2012-05-25 23:21:42 -04:00
|
|
|
@redis.verify
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|