From 03e005eeee2c31a0ff8fe48ddc0f11966b9c2a4e Mon Sep 17 00:00:00 2001 From: Oleksiy Kovyrin Date: Wed, 16 Oct 2024 15:58:08 -0400 Subject: [PATCH] Test timeouts with the new acquire methods --- test/resource_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/resource_test.rb b/test/resource_test.rb index dad62edf..52a61a0c 100644 --- a/test/resource_test.rb +++ b/test/resource_test.rb @@ -171,6 +171,25 @@ def test_acquire_timeout assert_equal(1, timeouts) end + def test_acquire_and_release_timeout + resource = create_resource(:testing, tickets: 1, timeout: 1) + start_time = Time.now.to_f + + # Grab the only ticket + resource.acquire_semaphore + + # Wait for the timeout trying to get a ticket, then catch the exception + assert_raises(Semian::TimeoutError) do + resource.acquire_semaphore + end + + # Should work now + resource.release_semaphore + + # Ensure we actually waited for the timeout + assert_in_delta(1, Time.now.to_f - start_time, EPSILON) + end + def test_acquire_timeout_override skip("Never tested correctly")