1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Close FDs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-30 14:50:42 +00:00
parent 60cb6f6eaa
commit 69105a1724
2 changed files with 51 additions and 44 deletions

View file

@ -14,10 +14,15 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
end end
def get_res_body(res) def get_res_body(res)
if defined? res.body.read body = res.body
res.body.read if defined? body.read
begin
body.read
ensure
body.close
end
else else
res.body body
end end
end end

View file

@ -48,64 +48,66 @@ module WEBrick
end end
def test_send_body_io def test_send_body_io
body_r, body_w = IO.pipe IO.pipe {|body_r, body_w|
body_w.write 'hello'
body_w.close
body_w.write 'hello' @res.body = body_r
body_w.close
@res.body = body_r IO.pipe {|r, w|
r, w = IO.pipe @res.send_body w
@res.send_body w w.close
w.close assert_equal 'hello', r.read
}
assert_equal 'hello', r.read }
end end
def test_send_body_string def test_send_body_string
@res.body = 'hello' @res.body = 'hello'
r, w = IO.pipe IO.pipe {|r, w|
@res.send_body w
@res.send_body w w.close
w.close assert_equal 'hello', r.read
}
assert_equal 'hello', r.read
end end
def test_send_body_string_io def test_send_body_string_io
@res.body = StringIO.new 'hello' @res.body = StringIO.new 'hello'
r, w = IO.pipe IO.pipe {|r, w|
@res.send_body w
@res.send_body w w.close
w.close assert_equal 'hello', r.read
}
assert_equal 'hello', r.read
end end
def test_send_body_io_chunked def test_send_body_io_chunked
@res.chunked = true @res.chunked = true
body_r, body_w = IO.pipe IO.pipe {|body_r, body_w|
body_w.write 'hello' body_w.write 'hello'
body_w.close body_w.close
@res.body = body_r @res.body = body_r
r, w = IO.pipe IO.pipe {|r, w|
@res.send_body w
@res.send_body w w.close
w.close r.binmode
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
r.binmode }
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read }
end end
def test_send_body_string_chunked def test_send_body_string_chunked
@ -113,14 +115,14 @@ module WEBrick
@res.body = 'hello' @res.body = 'hello'
r, w = IO.pipe IO.pipe {|r, w|
@res.send_body w
@res.send_body w w.close
w.close r.binmode
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
r.binmode }
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
end end
def test_send_body_string_io_chunked def test_send_body_string_io_chunked
@ -128,14 +130,14 @@ module WEBrick
@res.body = StringIO.new 'hello' @res.body = StringIO.new 'hello'
r, w = IO.pipe IO.pipe {|r, w|
@res.send_body w
@res.send_body w w.close
w.close r.binmode
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
r.binmode }
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
end end
end end
end end