Skip to content

Commit f50c7e9

Browse files
committed
Refactored buggy timer test.
1 parent 3ef172d commit f50c7e9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

spec/concurrent/utility/timer_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'hitimes'
2+
13
module Concurrent
24

35
describe '#timer' do
@@ -15,13 +17,12 @@ module Concurrent
1517
end
1618

1719
it 'executes the block after the given number of seconds' do
18-
start = Time.now.to_f
1920
latch = CountDownLatch.new(1)
20-
Concurrent::timer(0.1){ latch.count_down }
21-
latch.wait(1)
22-
diff = Time.now.to_f - start
23-
expect(diff).to be > 0.09
24-
expect(diff).to be < 0.5
21+
duration = Hitimes::Interval.measure do
22+
Concurrent::timer(0.1){ latch.count_down }
23+
latch.wait(1)
24+
end
25+
expect(duration).to be_within(0.05).of(0.1)
2526
end
2627

2728
it 'suppresses exceptions thrown by the block' do

0 commit comments

Comments
 (0)