Sha256: c2a21dd68f1b046756675b36b511e08befd0672ca2214cb9c1d3d50d31eb2fbe

Contents?: true

Size: 549 Bytes

Versions: 2

Compression:

Stored size: 549 Bytes

Contents

require_relative 'helper'

class TestLock < Sidetiq::TestCase
  def test_locking
    lock_name = SecureRandom.hex(8)
    key = SecureRandom.hex(8)

    Sidekiq.redis do |redis|
      redis.set(key, 0)

      5.times.map do
        Thread.start do
          locked(lock_name) do |r|
            sleep 0.1
            r.incr(key)
          end
        end
      end.each(&:join)

      assert_equal "1", redis.get(key)
    end
  end

  def locked(lock_name)
    Sidetiq::Lock.new(lock_name).synchronize do |redis|
      yield redis
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidetiq-0.3.7 test/test_lock.rb
sidetiq-0.3.6 test/test_lock.rb