diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-02-27 13:00:26 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-02-27 13:00:26 +0100 |
commit | 36dde35e029c7a6607e6c674062ce6fc7a51c0bd (patch) | |
tree | 47f9c820a93d5b9a68f7e903cc01ee607913e2dd /spec/ruby/core/io/close_spec.rb | |
parent | dbea0be13dc1f44833eca43a73f3ab898fa27c15 (diff) | |
download | ruby-36dde35e029c7a6607e6c674062ce6fc7a51c0bd.tar.gz |
Update to ruby/spec@37e52e5
Diffstat (limited to 'spec/ruby/core/io/close_spec.rb')
-rw-r--r-- | spec/ruby/core/io/close_spec.rb | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index dda82b34de..eb560eaf67 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -45,19 +45,36 @@ describe "IO#close" do end it 'raises an IOError with a clear message' do - read_io, write_io = IO.pipe - going_to_read = false - thread = Thread.new do - -> do - going_to_read = true - read_io.read - end.should raise_error(IOError, 'stream closed in another thread') - end - - Thread.pass until going_to_read && thread.stop? - read_io.close - thread.join - write_io.close + matching_exception = nil + + -> do + IOSpecs::THREAD_CLOSE_RETRIES.times do + read_io, write_io = IO.pipe + going_to_read = false + + thread = Thread.new do + begin + going_to_read = true + read_io.read + rescue IOError => ioe + if ioe.message == IOSpecs::THREAD_CLOSE_ERROR_MESSAGE + matching_exception = ioe + end + # try again + end + end + + # best attempt to ensure the thread is actually blocked on read + Thread.pass until going_to_read && thread.stop? + sleep(0.001) + + read_io.close + thread.join + write_io.close + + matching_exception&.tap {|ex| raise ex} + end + end.should raise_error(IOError, IOSpecs::THREAD_CLOSE_ERROR_MESSAGE) end end |