Sha256: 7d2d6ae4b4cf552d0989d8c509cfaa7251b9f29ccf2bf00ec65fb04d9cdec4f3

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

require_relative 'helper'
require 'sidekiq/scheduled'

class TestScheduling < Sidekiq::Test
  describe 'middleware' do
    class ScheduledWorker
      include Sidekiq::Worker
      sidekiq_options :queue => :custom_queue
      def perform(x)
      end
    end

    it 'schedules jobs' do
      ss = Sidekiq::ScheduledSet.new
      ss.clear

      assert_equal 0, ss.size

      assert ScheduledWorker.perform_in(600, 'mike')
      assert_equal 1, ss.size

      assert ScheduledWorker.perform_in(1.month, 'mike')
      assert_equal 2, ss.size

      assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
      assert_equal 3, ss.size

      q = Sidekiq::Queue.new("custom_queue")
      qs = q.size
      assert ScheduledWorker.perform_in(-300, 'mike')
      assert_equal 3, ss.size
      assert_equal qs+1, q.size

      assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
      assert_equal 5, ss.size
    end

    it 'removes the enqueued_at field when scheduling' do
      ss = Sidekiq::ScheduledSet.new
      ss.clear

      assert ScheduledWorker.perform_in(1.month, 'mike')
      job = ss.first
      assert job['created_at']
      refute job['enqueued_at']
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sidekiq-4.1.1 test/test_scheduling.rb
sidekiq-4.1.0 test/test_scheduling.rb
sidekiq-3.5.4 test/test_scheduling.rb
sidekiq-4.0.2 test/test_scheduling.rb
sidekiq-4.0.1 test/test_scheduling.rb
sidekiq-4.0.0 test/test_scheduling.rb
sidekiq-4.0.0.pre2 test/test_scheduling.rb
sidekiq-3.5.3 test/test_scheduling.rb
sidekiq-4.0.0.pre1 test/test_scheduling.rb
sidekiq-3.5.2 test/test_scheduling.rb
sidekiq-3.5.1 test/test_scheduling.rb