Sha256: 2bb000b91aefbc94a621855e5e767a9e0a58bcf3690b6abcb0657e50ad645b01

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

require 'helper'
require 'sidekiq/scheduled'

class TestScheduling < Sidekiq::Test
  describe 'middleware' do
    before do
      @redis = Minitest::Mock.new
      # Ugh, this is terrible.
      Sidekiq.instance_variable_set(:@redis, @redis)
      def @redis.multi; [yield] * 2 if block_given?; end
      def @redis.with; yield self; end
    end

    class ScheduledWorker
      include Sidekiq::Worker
      sidekiq_options :queue => :custom_queue
      def perform(x)
      end
    end

    it 'schedules a job via interval' do
      @redis.expect :zadd, true, ['schedule', Array]
      assert ScheduledWorker.perform_in(600, 'mike')
      @redis.verify
    end

    it 'schedules a job via timestamp' do
      @redis.expect :zadd, true, ['schedule', Array]
      assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
      @redis.verify
    end

    it 'schedules job right away on negative timestamp/interval' do
      @redis.expect :sadd,  true, ['queues', 'custom_queue']
      @redis.expect :lpush, true, ['queue:custom_queue', Array]
      assert ScheduledWorker.perform_in(-300, 'mike')
      @redis.verify
    end

    it 'schedules multiple jobs at once' do
      @redis.expect :zadd, true, ['schedule', Array]
      assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
      @redis.verify
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sidekiq-2.17.8 test/test_scheduling.rb
sidekiq-2.17.7 test/test_scheduling.rb
sidekiq-2.17.6 test/test_scheduling.rb
sidekiq-2.17.5 test/test_scheduling.rb
sidekiq-2.17.4 test/test_scheduling.rb
sidekiq-2.17.3 test/test_scheduling.rb
sidekiq-2.17.2 test/test_scheduling.rb
sidekiq-2.17.1 test/test_scheduling.rb
sidekiq-2.17.0 test/test_scheduling.rb