Skip to content

Commit

Permalink
Test timeouts with the new acquire methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kovyrin committed Oct 16, 2024
1 parent 4e17acf commit 03e005e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 03e005e

Please sign in to comment.