From edaa6d303adfb4ae0dead33a337d1c22d7aaacfb Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 2 Oct 2026 08:47:55 +0900 Subject: [PATCH] Close the Dirs created by Dir.for_fd in test_for_fd Dir.for_fd takes ownership of the descriptor, so passing dir.fileno left two unclosed Dirs owning the same fd once dir was closed. Their finalizers later closed whatever file reused that number, which made FileTestSingletonTest fail with Errno::EBADF on ruby/ruby's macOS CI. Give each call its own descriptor and close the returned Dir. https://github.com/ruby/ruby/actions/runs/36829284827 Co-Authored-By: Claude Opus 5.5 --- test/stdlib/Dir_test.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/test/stdlib/Dir_test.rb b/test/stdlib/Dir_test.rb index d98130acb4..895c8c5bed 100644 --- a/test/stdlib/Dir_test.rb +++ b/test/stdlib/Dir_test.rb @@ -133,17 +133,10 @@ def test_foreach end def test_for_fd - dir = Dir.new(Dir.pwd) - fd = dir.fileno - - with_int(fd) do |int| - assert_send_type( - "(::int) -> ::Dir", - Dir, :for_fd, int - ) - end - ensure - dir&.close + assert_send_type("(::int) -> ::Dir", + Dir, :for_fd, IO.sysopen(Dir.pwd)).close + assert_send_type("(::int) -> ::Dir", + Dir, :for_fd, ToInt.new(IO.sysopen(Dir.pwd))).close end def test_getwd