Skip to content

Commit

Permalink
Fix idle load computation. (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jun 23, 2024
1 parent a2074aa commit 46deff9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/io/event/selector/select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,8 @@ def select(duration = nil)
duration = 0 unless @ready.empty?
error = nil

if duration
if duration > 0
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
if duration&.>(0)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
else
@idle_duration = 0.0
end
Expand Down
9 changes: 7 additions & 2 deletions test/io/event/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ def transfer

with '#idle_duration' do
it 'can report idle duration' do
selector.select(0.01)
expect(selector.idle_duration).to be > 0.0
10.times do
selector.select(0.001)
expect(selector.idle_duration).to be > 0.0

selector.select(0)
expect(selector.idle_duration).to be == 0.0
end
end
end

Expand Down

0 comments on commit 46deff9

Please sign in to comment.