Sha256: a622e015ad52dbb450d52e143b36d91d10d33603accf9b7daa842b5c5336c868

Contents?: true

Size: 1.94 KB

Versions: 10

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'
require 'sidekiq/api'
require 'sidekiq/worker'
require 'sidekiq_unique_jobs/server/middleware'
require 'sidekiq_unique_jobs/client/middleware'
require 'sidekiq_unique_jobs/sidekiq_unique_ext'

RSpec.describe 'Sidekiq::Api' do
  before do
    Sidekiq.redis = REDIS
    Sidekiq.redis(&:flushdb)
  end

  let(:item) do
    { 'class' => JustAWorker,
      'queue' => 'testqueue',
      'args'  => [foo: 'bar'] }
  end

  def unique_key
    SidekiqUniqueJobs::UniqueArgs.digest(
      'class' => JustAWorker,
      'queue' => 'testqueue',
      'args'  => [foo: 'bar'],
      'at'    => (Date.today + 1).to_time.to_i)
  end

  def schedule_job
    JustAWorker.perform_in(60 * 60 * 3, foo: 'bar')
  end

  def perform_async
    JustAWorker.perform_async(foo: 'bar')
  end

  describe Sidekiq::SortedEntry::UniqueExtension, sidekiq_ver: '>= 3.1' do
    it 'deletes uniqueness lock on delete' do
      expect(schedule_job).to be_truthy

      Sidekiq::ScheduledSet.new.each(&:delete)
      Sidekiq.redis do |c|
        expect(c.exists(unique_key)).to be_falsy
      end

      expect(schedule_job).to be_truthy
    end
  end

  describe Sidekiq::Job::UniqueExtension do
    it 'deletes uniqueness lock on delete' do
      jid = perform_async
      Sidekiq::Queue.new('testqueue').find_job(jid).delete
      Sidekiq.redis do |c|
        expect(c.exists(unique_key)).to be_falsy
      end
      expect(true).to be_truthy
    end
  end

  describe Sidekiq::Queue::UniqueExtension do
    it 'deletes uniqueness locks on clear' do
      perform_async
      Sidekiq::Queue.new('testqueue').clear
      Sidekiq.redis do |c|
        expect(c.exists(unique_key)).to be_falsy
      end
    end
  end

  describe Sidekiq::JobSet::UniqueExtension, sidekiq_ver: '>= 3.1' do
    it 'deletes uniqueness locks on clear' do
      schedule_job
      Sidekiq::JobSet.new('schedule').clear
      Sidekiq.redis do |c|
        expect(c.exists(unique_key)).to be_falsy
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.17 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.16 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.15 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.13 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.12 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.11 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.10 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.9 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.8 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb
sidekiq-unique-jobs-4.0.7 spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb