From f4bab19205b099a7e3d10533bbb8054726a9dfff Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 25 Aug 2023 22:35:09 +1200 Subject: [PATCH] Add test for timeout behaviour. --- test/async/task.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/async/task.rb b/test/async/task.rb index dd7fdcd3..46062c19 100644 --- a/test/async/task.rb +++ b/test/async/task.rb @@ -596,6 +596,23 @@ def after expect(state).to be == :timeout end + it "will timeout while getting from stdin" do + error = nil + + reactor.async do |task| + begin + task.with_timeout(0.1) {STDIN.read(1)} + rescue Async::TimeoutError => error + puts "Error: #{error}" + # Ignore. + end + end + + reactor.run + + expect(error).to be_a(Async::TimeoutError) + end + it "won't timeout if execution completes in time" do state = nil