Skip to content

Commit

Permalink
Allow this test to retry 10 times
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
headius committed Nov 6, 2023
1 parent 5ff5f25 commit f012640
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions test/jruby/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit f012640

Please sign in to comment.