Sha256: fb8f202e6cf19e63608961fee9d6ef1b800d2b796bc165dc2e2d2037306c7a86

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'test_helper'

module Sidekiq
  module Lock
    describe Middleware do
      before do
        if Sidekiq::VERSION >= '7'
          Sidekiq.configure_server do |config|
            config.redis = { url: REDIS_URL }
          end
        else
          Sidekiq.redis = REDIS
        end
        Sidekiq.redis { |c| c.flushdb }
        reset_lock_variable!
      end

      let(:handler) { Sidekiq::Lock::Middleware.new }

      it 'sets lock variable with provided static lock options' do
        handler.call(LockWorker.new, { 'class' => LockWorker, 'args' => [] }, 'default') do
          true
        end

        assert_kind_of RedisLock, lock_container_variable
      end

      it 'sets lock variable with provided dynamic options' do
        handler.call(DynamicLockWorker.new, { 'class' => DynamicLockWorker, 'args' => [1234, 1000] }, 'default') do
          true
        end

        assert_equal "lock:1234", lock_container_variable.name
        assert_equal 2000, lock_container_variable.timeout
      end

      it 'sets nothing for workers without lock options' do
        handler.call(RegularWorker.new, { 'class' => RegularWorker, 'args' => [] }, 'default') do
          true
        end

        assert_nil lock_container_variable
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-lock-0.6.0 test/lib/middleware_test.rb