Skip to content

Commit

Permalink
Proper way to do elapsed time calc
Browse files Browse the repository at this point in the history
  • Loading branch information
kovyrin committed Oct 16, 2024
1 parent 849422e commit eefa8fd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_acquire_timeout

def test_acquire_and_release_timeout
resource = create_resource(:testing, tickets: 1, timeout: 1)
start_time = Time.now.to_f
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

# Grab the only ticket
resource.acquire_semaphore
Expand All @@ -182,12 +182,13 @@ def test_acquire_and_release_timeout
assert_raises(Semian::TimeoutError) do
resource.acquire_semaphore
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

# Should work now
resource.release_semaphore

# Ensure we actually waited for the timeout
assert_in_delta(1, Time.now.to_f - start_time, EPSILON)
assert_in_delta(1, end_time - start_time, EPSILON)
end

def test_release_semaphore_without_acquire
Expand Down

0 comments on commit eefa8fd

Please sign in to comment.