Sha256: 9607eec76bf9e36e4f0e83091ac0b57ac748f6a1991cf6c56cb7cb591f10d5f2

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module Redlock
  class Client
    attr_writer :testing_mode

    alias_method :try_lock_instances_without_testing, :try_lock_instances

    def try_lock_instances(resource, ttl, extend)
      if @testing_mode == :bypass
        {
          validity: ttl,
          resource: resource,
          value: extend ? extend.fetch(:value) : SecureRandom.uuid
        }
      elsif @testing_mode == :fail
        false
      else
        try_lock_instances_without_testing resource, ttl, extend
      end
    end

    alias_method :unlock_without_testing, :unlock

    def unlock(lock_info)
      unlock_without_testing lock_info unless @testing_mode == :bypass
    end

    class RedisInstance
      alias_method :load_scripts_without_testing, :load_scripts

      def load_scripts
        load_scripts_without_testing
      rescue Redis::CommandError
        # FakeRedis doesn't have #script, but doesn't need it either.
        raise unless defined?(::FakeRedis)
      rescue NoMethodError
        raise unless defined?(::MockRedis)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redlock-0.1.7 lib/redlock/testing.rb
redlock-0.1.6 lib/redlock/testing.rb
redlock-0.1.5 lib/redlock/testing.rb