File: nesting_test.rb

package info (click to toggle)
ruby-with-advisory-lock 5.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 232 kB
  • sloc: ruby: 747; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'test_helper'

class LockNestingTest < GemTestCase
  setup do
    @prior_prefix = ENV['WITH_ADVISORY_LOCK_PREFIX']
    ENV['WITH_ADVISORY_LOCK_PREFIX'] = nil
  end

  teardown do
    ENV['WITH_ADVISORY_LOCK_PREFIX'] = @prior_prefix
  end

  test "doesn't request the same lock twice" do
    impl = WithAdvisoryLock::Base.new(nil, nil, nil)
    assert_empty(impl.lock_stack)
    Tag.with_advisory_lock('first') do
      assert_equal(%w[first], impl.lock_stack.map(&:name))
      # Even MySQL should be OK with this:
      Tag.with_advisory_lock('first') do
        assert_equal(%w[first], impl.lock_stack.map(&:name))
      end
      assert_equal(%w[first], impl.lock_stack.map(&:name))
    end
    assert_empty(impl.lock_stack)
  end
end