Sha256: d1d5efd33dd201bc02b0452046074819ae8e85411c1a9db79859f8220b8681ac

Contents?: true

Size: 1.06 KB

Versions: 62

Compression:

Stored size: 1.06 KB

Contents

require 'test_helper'

module Workarea
  class LockTest < TestCase
    teardown :unlock

    def unlock
      Lock.destroy!('lock_test', 'foo')
    end

    def test_find
      Lock.create!('lock_test', 'foo')

      assert_equal('foo', Lock.find('lock_test'))
      assert_nil(Lock.find('lock_test_two'))

      unlock
      assert_nil(Lock.find('lock_test'))
    end

    def test_exists?
      Lock.create!('lock_test', 'foo')

      assert(Lock.exists?('lock_test'))
      refute(Lock.exists?('lock_test_two'))
    end

    def test_create!
      assert(Lock.create!('lock_test', 'foo'))
      assert_raises(Lock::Locked) { Lock.create!('lock_test', 'bar') }
      assert(Lock.create!('lock_test', 'foo', nx: false))
    end

    def test_destroy!
      Lock.create!('lock_test', 'foo')

      assert(Lock.destroy!('lock_test', 'bar'))
      assert(Lock.destroy!('lock_test', 'foo'))

      Lock.create!('lock_test', 'foo', ex: 1)
      sleep 2 # wait for lock to expire

      refute(Lock.exists?('lock_test'))
      assert(Lock.destroy!('lock_test', 'foo'))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 test/models/workarea/lock_test.rb
workarea-core-3.4.36 test/models/workarea/lock_test.rb
workarea-core-3.5.14 test/models/workarea/lock_test.rb
workarea-core-3.4.35 test/models/workarea/lock_test.rb
workarea-core-3.5.13 test/models/workarea/lock_test.rb
workarea-core-3.4.34 test/models/workarea/lock_test.rb
workarea-core-3.5.12 test/models/workarea/lock_test.rb
workarea-core-3.4.33 test/models/workarea/lock_test.rb
workarea-core-3.5.11 test/models/workarea/lock_test.rb
workarea-core-3.5.10 test/models/workarea/lock_test.rb
workarea-core-3.4.32 test/models/workarea/lock_test.rb
workarea-core-3.5.9 test/models/workarea/lock_test.rb
workarea-core-3.4.31 test/models/workarea/lock_test.rb
workarea-core-3.5.8 test/models/workarea/lock_test.rb
workarea-core-3.4.30 test/models/workarea/lock_test.rb
workarea-core-3.5.7 test/models/workarea/lock_test.rb
workarea-core-3.4.29 test/models/workarea/lock_test.rb
workarea-core-3.5.6 test/models/workarea/lock_test.rb
workarea-core-3.4.28 test/models/workarea/lock_test.rb
workarea-core-3.5.5 test/models/workarea/lock_test.rb