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")