Skip to content

Commit 857d7fb

Browse files
committed
Spec that IO#flush raises Errno::EPIPE if the read end is closed and sync=false
1 parent 75a281b commit 857d7fb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

spec/ruby/core/io/flush_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,33 @@
55
it "raises IOError on closed stream" do
66
lambda { IOSpecs.closed_io.flush }.should raise_error(IOError)
77
end
8+
9+
describe "on a pipe" do
10+
before :each do
11+
@r, @w = IO.pipe
12+
end
13+
14+
after :each do
15+
@r.close
16+
begin
17+
@w.close
18+
rescue Errno::EPIPE
19+
end
20+
end
21+
22+
# [ruby-core:90895] MJIT worker may leave fd open in a forked child.
23+
# For instance, MJIT creates a worker before @r.close with fork(), @r.close happens,
24+
# and the MJIT worker keeps the pipe open until the worker execve().
25+
# TODO: consider acquiring GVL from MJIT worker.
26+
guard_not -> { defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? } do
27+
it "raises Errno::EPIPE if sync=false and the read end is closed" do
28+
@w.sync = false
29+
@w.write "foo"
30+
@r.close
31+
32+
-> { @w.flush }.should raise_error(Errno::EPIPE, /Broken pipe/)
33+
-> { @w.close }.should raise_error(Errno::EPIPE, /Broken pipe/)
34+
end
35+
end
36+
end
837
end

0 commit comments

Comments
 (0)