about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-25 23:01:01 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-25 23:02:01 +0000
commit025a67afc97ce65d30bebd61bedf20066d1874c6 (patch)
treeaf21ac8c5c724813eae56b188161c24955ca6638 /test
parent9bece9d13543743e2a0fdc6eab56c54098d4d0e6 (diff)
downloadyahns-025a67afc97ce65d30bebd61bedf20066d1874c6.tar.gz
We need to prevent FD leakage on Ruby 1.9.3
Diffstat (limited to 'test')
-rw-r--r--test/helper.rb4
-rw-r--r--test/test_bin.rb2
-rw-r--r--test/test_output_buffering.rb4
-rw-r--r--test/test_server.rb2
-rw-r--r--test/test_wbuf.rb6
5 files changed, 11 insertions, 7 deletions
diff --git a/test/helper.rb b/test/helper.rb
index 730b96c..3f141e4 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -114,6 +114,10 @@ class IO
   end
 end if ! IO.method_defined?(:nread) && RUBY_PLATFORM =~ /linux/
 
+def cloexec_pipe
+  IO.pipe.each { |io| io.close_on_exec = true }
+end
+
 require 'yahns'
 
 # needed for parallel (MT) tests)
diff --git a/test/test_bin.rb b/test/test_bin.rb
index 71333e7..8944eb3 100644
--- a/test/test_bin.rb
+++ b/test/test_bin.rb
@@ -40,7 +40,7 @@ class TestBin < Testcase
     cfg.puts "  listen ENV['YAHNS_TEST_LISTEN']"
     cfg.puts "end"
     @cmd.concat(%W(-D -c #{cfg.path}))
-    addr = IO.pipe
+    addr = cloexec_pipe
     pid = fork do
       opts = { close_others: true }
       addr[0].close
diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb
index afb23f8..ae9b449 100644
--- a/test/test_output_buffering.rb
+++ b/test/test_output_buffering.rb
@@ -77,8 +77,8 @@ class TestOutputBuffering < Testcase
       # HTTP/0.9
       c = get_tcp_client(host, port)
       c.write("GET /\r\n\r\n")
-      md5in = IO.pipe
-      md5out = IO.pipe
+      md5in = cloexec_pipe
+      md5out = cloexec_pipe
       sleep(delay) if delay
       md5pid = Process.spawn("md5sum", :in => md5in[0], :out => md5out[1])
       md5in[0].close
diff --git a/test/test_server.rb b/test/test_server.rb
index c277896..d87f617 100644
--- a/test/test_server.rb
+++ b/test/test_server.rb
@@ -193,7 +193,7 @@ class TestServer < Testcase
     msgs = %w(ZZ zz)
     err = @err
     cfg = Yahns::Config.new
-    bpipe = IO.pipe
+    bpipe = cloexec_pipe
     host, port = @srv.addr[3], @srv.addr[1]
     cfg.instance_eval do
       ru = lambda { |e|
diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb
index 0923eb0..44ac74e 100644
--- a/test/test_wbuf.rb
+++ b/test/test_wbuf.rb
@@ -16,7 +16,7 @@ class TestWbuf < Testcase
       assert_equal "HIHI", b.read(4)
       nr.times { wbuf.wbuf_write(a, buf) }
       assert_equal :wait_writable, wbuf.wbuf_flush(a)
-      done = IO.pipe
+      done = cloexec_pipe
       thr = Thread.new do
         rv = []
         until rv[-1] == persist
@@ -86,7 +86,7 @@ class TestWbuf < Testcase
   end
 
   def test_wbuf_flush_close
-    pipe = IO.pipe
+    pipe = cloexec_pipe
     persist = true
     wbuf = Yahns::Wbuf.new(pipe[0], persist)
     refute wbuf.respond_to?(:close) # we don't want this for HttpResponse body
@@ -103,7 +103,7 @@ class TestWbuf < Testcase
     assert_equal thr, thr.join(5)
     assert_equal :wait_writable, rv
 
-    done = IO.pipe
+    done = cloexec_pipe
     thr = Thread.new do
       rv = []
       until rv[-1] == persist