From fe1960135031e1b7011ddda0df94056a43da246e Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 8 Nov 2024 20:12:11 +1300 Subject: [PATCH] Test `warn` rather than ignoring it - fix various tests. --- config/sus.rb | 2 -- test/async/task.rb | 15 +++++++++++++-- test/async/waiter.rb | 6 +++++- test/async/wrapper.rb | 12 ------------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/config/sus.rb b/config/sus.rb index ced71241..be5cd75b 100644 --- a/config/sus.rb +++ b/config/sus.rb @@ -5,5 +5,3 @@ require "covered/sus" include Covered::Sus - -ENV["CONSOLE_LEVEL"] ||= "fatal" diff --git a/test/async/task.rb b/test/async/task.rb index f31f9e95..27beaef0 100644 --- a/test/async/task.rb +++ b/test/async/task.rb @@ -126,6 +126,8 @@ reactor.run do expect do reactor.async do |task| + expect(task).to receive(:warn).and_return(nil) + raise "boom" end.wait end.to raise_exception(RuntimeError, message: be =~ /boom/) @@ -156,6 +158,8 @@ expect do task = reactor.async do |task| + expect(task).to receive(:warn).and_return(nil) + raise "boom" end end.not.to raise_exception @@ -624,6 +628,10 @@ def sleep_forever it "contains useful backtrace" do task = Async do |task| + expect(task).to receive(:warn).with_options(have_keys( + exception: be_a(Async::TimeoutError), + )).and_return(nil) + task.with_timeout(0.001) do sleep_forever end @@ -686,6 +694,8 @@ def sleep_forever reactor.run do error_task = reactor.async do |task| + expect(task).to receive(:warn).and_return(nil) + raise RuntimeError, "brain not provided" end @@ -726,7 +736,9 @@ def sleep_forever with "#result" do it "does not raise exception" do - task = reactor.async do + task = reactor.async do |task| + expect(task).to receive(:warn).and_return(nil) + raise "The space time converter has failed." end @@ -746,7 +758,6 @@ def sleep_forever expect(task.result).to be_nil - Console.debug(self) {"Stopping task..."} task.stop expect(task.result).to be_nil diff --git a/test/async/waiter.rb b/test/async/waiter.rb index e94ff20c..21dbf437 100644 --- a/test/async/waiter.rb +++ b/test/async/waiter.rb @@ -35,7 +35,11 @@ end it "can wait for tasks even when exceptions occur" do - waiter.async do + waiter.async do |task| + expect(task).to receive(:warn).with_options(have_keys( + exception: be_a(RuntimeError), + )).and_return(nil) + raise "Something went wrong" end diff --git a/test/async/wrapper.rb b/test/async/wrapper.rb index 057e2cb2..3a42cf69 100644 --- a/test/async/wrapper.rb +++ b/test/async/wrapper.rb @@ -52,18 +52,6 @@ it "can wait to be writable" do expect(input.wait_writable).to be_truthy end - - it "can be cancelled while waiting to be readable" do - task = reactor.async do - input.wait_readable - end - - output.close - - expect do - task.wait - end.to raise_exception(IOError) - end end with "#wait_priority" do