Sha256: 22f7a23320a38136bd4941a3786e7f6c43942806defece75440d77e57e2e4a35

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require_relative 'helper'

class TestShedulable < Sidetiq::TestCase
  class FakeWorker
    include Sidetiq::Schedulable
  end

  def test_resheduling
    last_run = (Time.now - 100).to_f
    next_run = (Time.now + 100).to_f

    Sidekiq.redis do |redis|
      redis.set "sidetiq:TestShedulable::FakeWorker:last", last_run
      redis.set "sidetiq:TestShedulable::FakeWorker:next", next_run
    end

    assert FakeWorker.schedule_description == nil

    FakeWorker.schedule = nil
    FakeWorker.recurrence { minutely }

    assert FakeWorker.schedule_description == "Minutely"
    assert FakeWorker.last_scheduled_occurrence == -1.0
    assert FakeWorker.next_scheduled_occurrence == -1.0

    Sidekiq.redis do |redis|
      redis.set "sidetiq:TestShedulable::FakeWorker:last", last_run
      redis.set "sidetiq:TestShedulable::FakeWorker:next", next_run
    end

    FakeWorker.schedule = nil
    FakeWorker.recurrence { minutely }

    assert FakeWorker.schedule_description == "Minutely"
    assert FakeWorker.last_scheduled_occurrence == last_run
    assert FakeWorker.next_scheduled_occurrence == next_run

    FakeWorker.schedule = nil
    FakeWorker.recurrence { hourly }

    assert FakeWorker.schedule_description == "Hourly"
    assert FakeWorker.last_scheduled_occurrence == -1.0
    assert FakeWorker.next_scheduled_occurrence == -1.0
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidetiq-0.6.1 test/test_schedulable.rb
sidetiq-0.6.0 test/test_schedulable.rb