From 46deff96ad246b5661977af76cb831ab6caabbc4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 23 Jun 2024 11:28:30 +0900 Subject: [PATCH] Fix idle load computation. (#110) --- lib/io/event/selector/select.rb | 6 ++---- test/io/event/selector.rb | 9 +++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/io/event/selector/select.rb b/lib/io/event/selector/select.rb index 588b4e0..40e885b 100644 --- a/lib/io/event/selector/select.rb +++ b/lib/io/event/selector/select.rb @@ -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 diff --git a/test/io/event/selector.rb b/test/io/event/selector.rb index 3214ead..760369a 100644 --- a/test/io/event/selector.rb +++ b/test/io/event/selector.rb @@ -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