Skip to content

Commit

Permalink
! SleeperNotifier#notifyAfter would break if passed negative value.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledestin committed Nov 8, 2013
1 parent c3fc722 commit 2c76521
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/frugal_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def latestDelay
def notifyAfter sec
synchronize {
sleep 0.01 until @thread.status == 'sleep'
sec = 0 if sec < 0
@latestDelay = sec
@thread.wakeup
}
Expand Down
7 changes: 7 additions & 0 deletions spec/frugal_timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def new_timeout_request_thread sec, res, resMutex
(Time.now - start - 0.5).round(2).should <= 0.01
end

it 'handles negative delay' do
FrugalTimeout::MonotonicTime.measure {
sleeper.notifyAfter -1
queue.shift
}.round(1).should == 0
end

it 'sends notification one time only for multiple requests' do
5.times { sleeper.notifyAfter 0.5 }
sleeper.notifyAfter 0.4
Expand Down

0 comments on commit 2c76521

Please sign in to comment.