summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-30 14:50:42 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-30 14:50:42 +0000
commit69105a1724d5223025fa35488cb860f90f2cba1d (patch)
tree2373e137187754ec0e059cc36e925ef0d8d304e3 /test
parent60cb6f6eaad2eeafa7a8204b81d6becbb741d152 (diff)
Close FDs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/webrick/test_filehandler.rb11
-rw-r--r--test/webrick/test_httpresponse.rb84
2 files changed, 51 insertions, 44 deletions
diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb
index 10b6add147..bdbd4e26fa 100644
--- a/test/webrick/test_filehandler.rb
+++ b/test/webrick/test_filehandler.rb
@@ -14,10 +14,15 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
end
def get_res_body(res)
- if defined? res.body.read
- res.body.read
+ body = res.body
+ if defined? body.read
+ begin
+ body.read
+ ensure
+ body.close
+ end
else
- res.body
+ body
end
end
diff --git a/test/webrick/test_httpresponse.rb b/test/webrick/test_httpresponse.rb
index c9fb4ff3ae..1f85a920ca 100644
--- a/test/webrick/test_httpresponse.rb
+++ b/test/webrick/test_httpresponse.rb
@@ -48,64 +48,66 @@ module WEBrick
end
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'
- body_w.close
+ @res.body = body_r
- @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
def test_send_body_string
@res.body = 'hello'
- r, w = IO.pipe
-
- @res.send_body w
+ IO.pipe {|r, w|
+ @res.send_body w
- w.close
+ w.close
- assert_equal 'hello', r.read
+ assert_equal 'hello', r.read
+ }
end
def test_send_body_string_io
@res.body = StringIO.new 'hello'
- r, w = IO.pipe
-
- @res.send_body w
+ IO.pipe {|r, w|
+ @res.send_body w
- w.close
+ w.close
- assert_equal 'hello', r.read
+ assert_equal 'hello', r.read
+ }
end
def test_send_body_io_chunked
@res.chunked = true
- body_r, body_w = IO.pipe
+ IO.pipe {|body_r, body_w|
- body_w.write 'hello'
- body_w.close
+ body_w.write 'hello'
+ 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
def test_send_body_string_chunked
@@ -113,14 +115,14 @@ module WEBrick
@res.body = 'hello'
- r, w = IO.pipe
-
- @res.send_body w
+ IO.pipe {|r, 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
def test_send_body_string_io_chunked
@@ -128,14 +130,14 @@ module WEBrick
@res.body = StringIO.new 'hello'
- r, w = IO.pipe
-
- @res.send_body w
+ IO.pipe {|r, 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