diff options
author | Samuel Williams <[email protected]> | 2023-12-25 14:20:53 +1300 |
---|---|---|
committer | GitHub <[email protected]> | 2023-12-25 14:20:53 +1300 |
commit | 260bf60e52ffdfa625be1153624b0d123fc305f8 (patch) | |
tree | f473605a7b5fd59e6892f56bbc064aca7c71bdde /test/ruby/test_io_buffer.rb | |
parent | 5af64ff7db3d636201db68b9ba995131a04a8f7b (diff) |
Correctly release the underlying file mapping. (#9340)
* Avoiding using `Tempfile` which was retaining the file preventing it from unlinking.
Diffstat (limited to 'test/ruby/test_io_buffer.rb')
-rw-r--r-- | test/ruby/test_io_buffer.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index f7a6557a24..c4239101cf 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -519,23 +519,22 @@ class TestIOBuffer < Test::Unit::TestCase end def test_private - omit if RUBY_PLATFORM =~ /mswin|mingw/ + tmpdir = Dir.tmpdir + buffer_path = File.join(tmpdir, "buffer.txt") + File.write(buffer_path, "Hello World") - Tempfile.create("buffer.txt") do |io| - io.write("Hello World") - - buffer = IO::Buffer.map(io, nil, 0, IO::Buffer::PRIVATE) + File.open(buffer_path) do |file| + buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE) assert buffer.private? refute buffer.readonly? buffer.set_string("J") # It was not changed because the mapping was private: - io.seek(0) - assert_equal "Hello World", io.read + file.seek(0) + assert_equal "Hello World", file.read ensure buffer&.free - io&.close end end end |