From f0126405d057daa7f2a5e6a47559e774e9748a1b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 6 Nov 2023 15:16:17 -0600 Subject: [PATCH] Allow this test to retry 10 times The fileno mapping is managed globally for a given JRuby runtime and during testing there may be other threads still cleaning up and removing filenos from the mapping. We give this test ten tries to have the starting count and ending count match. This should help avoid intermittent failures like the following: ``` Failure: test_rubyio_fileno_mapping_leak(TestIO) /home/runner/work/jruby/jruby/test/jruby/test_io.rb:527:in `test_rubyio_fileno_mapping_leak' 524: io = org.jruby.RubyIO.new(JRuby.runtime, java.io.ByteArrayOutputStream.new) 525: 526: open_io_count = fileno_util.number_of_wrappers => 527: assert_equal(starting_count + 1, open_io_count) 528: 529: io.close 530: closed_io_count = fileno_util.number_of_wrappers ``` --- test/jruby/test_io.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/test/jruby/test_io.rb b/test/jruby/test_io.rb index 3648770618a..746eb035ba0 100644 --- a/test/jruby/test_io.rb +++ b/test/jruby/test_io.rb @@ -518,16 +518,30 @@ def test_stringio_gets_separator # JRUBY-6137 def test_rubyio_fileno_mapping_leak fileno_util = JRuby.runtime.fileno_util - starting_count = fileno_util.number_of_wrappers - # use a non-channel stream to ensure we use our mapping - io = org.jruby.RubyIO.new(JRuby.runtime, java.io.ByteArrayOutputStream.new) + # other test threads may still be cleaning up filenos, so we give a few rounds for this to settle + count = 0 + while count < 10 + starting_count = fileno_util.number_of_wrappers - open_io_count = fileno_util.number_of_wrappers - assert_equal(starting_count + 1, open_io_count) + # use a non-channel stream to ensure we use our mapping + io = org.jruby.RubyIO.new(JRuby.runtime, java.io.ByteArrayOutputStream.new) - io.close - closed_io_count = fileno_util.number_of_wrappers + open_io_count = fileno_util.number_of_wrappers + + io.close + closed_io_count = fileno_util.number_of_wrappers + + if starting_count == closed_io_count + break + end + + # either leaking or other threads are opening and closing; pause and try again + Thread.pass + end + + # proceed to assertions + assert_equal(starting_count + 1, open_io_count) assert_equal(starting_count, closed_io_count) end if RUBY_ENGINE == 'jruby'