From 7f911a614cab829fd98dcc3611a620558602b36c Mon Sep 17 00:00:00 2001 From: Oleksiy Kovyrin Date: Wed, 16 Oct 2024 11:30:55 -0400 Subject: [PATCH] Add a test for acquire/release --- test/resource_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/resource_test.rb b/test/resource_test.rb index 0e516e36..dad62edf 100644 --- a/test/resource_test.rb +++ b/test/resource_test.rb @@ -140,6 +140,22 @@ def test_acquire assert(acquired) end + def test_acquire_and_release_semaphore + resource = create_resource(:testing, tickets: 1) + + assert_equal(1, resource.count) + + begin + resource.acquire_semaphore + + assert_equal(0, resource.count) + ensure + resource.release_semaphore + + assert_equal(1, resource.count) + end + end + def test_acquire_return_val resource = create_resource(:testing, tickets: 1) val = resource.acquire { 1234 }