about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--test/server_helper.rb1
-rw-r--r--test/test_client_expire.rb8
-rw-r--r--test/test_client_max_body_size.rb8
-rw-r--r--test/test_output_buffering.rb12
-rw-r--r--test/test_server.rb16
5 files changed, 23 insertions, 22 deletions
diff --git a/test/server_helper.rb b/test/server_helper.rb
index 89276b8..71cb9d3 100644
--- a/test/server_helper.rb
+++ b/test/server_helper.rb
@@ -50,6 +50,7 @@ module ServerHelper
   def get_tcp_client(host, port, tries = 500)
     begin
       c = TCPSocket.new(host, port)
+      c.close_on_exec = true
       return c
     rescue Errno::ECONNREFUSED
       raise if tries < 0
diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb
index 3a41c8e..8ee914b 100644
--- a/test/test_client_expire.rb
+++ b/test/test_client_expire.rb
@@ -56,8 +56,8 @@ class TestClientExpire < Testcase
       ENV["YAHNS_FD"] = @srv.fileno.to_s
       srv.start.join
     end
-    f = TCPSocket.new(host, port)
-    s = TCPSocket.new(host, port)
+    f = get_tcp_client(host, port)
+    s = get_tcp_client(host, port)
     req = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
     s.write(req)
     str = Timeout.timeout(20) { s.readpartial(666) }
@@ -101,8 +101,8 @@ class TestClientExpire < Testcase
       ENV["YAHNS_FD"] = @srv.fileno.to_s
       srv.start.join
     end
-    f = TCPSocket.new(host, port)
-    s = TCPSocket.new(host, port)
+    f = get_tcp_client(host, port)
+    s = get_tcp_client(host, port)
     req = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
     s.write(req)
     str = Timeout.timeout(20) { s.readpartial(666) }
diff --git a/test/test_client_max_body_size.rb b/test/test_client_max_body_size.rb
index 24590ff..cdf8ce9 100644
--- a/test/test_client_max_body_size.rb
+++ b/test/test_client_max_body_size.rb
@@ -138,24 +138,24 @@ class TestClientMaxBodySize < Testcase
 
   def default_identity_checks(host, port, defmax = DEFMBS)
     if defmax >= 666
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write(identity_req(666))
       assert_equal "666", c.read.split(/\r\n\r\n/)[1]
       c.close
     end
 
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     c.write(identity_req(0))
     assert_equal "0", c.read.split(/\r\n\r\n/)[1]
     c.close
 
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     c.write(identity_req(defmax))
     assert_equal "#{defmax}", c.read.split(/\r\n\r\n/)[1]
     c.close
 
     toobig = defmax + 1
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     c.write(identity_req(toobig, false))
     assert_match(%r{\AHTTP/1\.[01] 413 }, Timeout.timeout(10) { c.read })
     c.close
diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb
index dc91aed..afb23f8 100644
--- a/test/test_output_buffering.rb
+++ b/test/test_output_buffering.rb
@@ -75,7 +75,7 @@ class TestOutputBuffering < Testcase
       assert_equal MD5.value, md5
     when :http09
       # HTTP/0.9
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write("GET /\r\n\r\n")
       md5in = IO.pipe
       md5out = IO.pipe
@@ -172,7 +172,7 @@ class TestOutputBuffering < Testcase
 
     # start with just a big header
     threads << Thread.new do
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write "GET / HTTP/1.0\r\n\r\n"
       begin
         sleep 1
@@ -192,7 +192,7 @@ class TestOutputBuffering < Testcase
     end
 
     threads << Thread.new do
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write "GET /COPYING HTTP/1.0\r\n\r\n"
       begin
         sleep 1
@@ -211,7 +211,7 @@ class TestOutputBuffering < Testcase
     end
 
     threads << Thread.new do
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write "GET /COPYING HTTP/1.0\r\nRange: bytes=5-46\r\n\r\n"
       begin
         sleep 1
@@ -268,7 +268,7 @@ class TestOutputBuffering < Testcase
     end
     threads = []
     threads << Thread.new do
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
       sleep(5) # wait for timeout
       assert_operator c.nread, :>, 0
@@ -276,7 +276,7 @@ class TestOutputBuffering < Testcase
     end
 
     threads << Thread.new do
-      c = TCPSocket.new(host, port)
+      c = get_tcp_client(host, port)
       c.write("GET /bh HTTP/1.1\r\nHost: example.com\r\n\r\n")
       sleep(5) # wait for timeout
       assert_operator c.nread, :>, 0
diff --git a/test/test_server.rb b/test/test_server.rb
index 6a3b1f1..25f4b44 100644
--- a/test/test_server.rb
+++ b/test/test_server.rb
@@ -24,7 +24,7 @@ class TestServer < Testcase
       srv.start.join
     end
     run_client(host, port) { |res| assert_equal "HI", res.body }
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
 
     # test pipelining
     r = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
@@ -85,7 +85,7 @@ class TestServer < Testcase
       ENV["YAHNS_FD"] = @srv.fileno.to_s
       srv.start.join
     end
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     buf = "PUT / HTTP/1.0\r\nContent-Length: 2\r\n\r\nHI"
     c.write(buf)
     IO.select([c], nil, nil, 5)
@@ -97,7 +97,7 @@ class TestServer < Testcase
 
     # pipelined oneshot
     buf = "PUT / HTTP/1.1\r\nContent-Length: 2\r\n\r\nHI"
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     c.write(buf + buf)
     buf = ""
     Timeout.timeout(10) do
@@ -164,7 +164,7 @@ class TestServer < Testcase
       ENV["YAHNS_FD"] = @srv.fileno.to_s
       srv.start.join
     end
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     buf = "PUT / HTTP/1.0\r\nTrailer:xbt\r\nTransfer-Encoding: chunked\r\n\r\n"
     c.write(buf)
     xbt = btype.to_s
@@ -239,8 +239,8 @@ class TestServer < Testcase
       srv.start.join
     end
     bpipe[0].close
-    a = TCPSocket.new(host, port)
-    b = TCPSocket.new(host, port)
+    a = get_tcp_client(host, port)
+    b = get_tcp_client(host, port)
     a.write("GET /sleep HTTP/1.0\r\n\r\n")
     r = IO.select([a], nil, nil, 4)
     assert r, "nothing ready"
@@ -312,7 +312,7 @@ class TestServer < Testcase
   end
 
   def run_client(host, port)
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     Net::HTTP.start(host, port) do |http|
       res = http.request(Net::HTTP::Get.new("/"))
       assert_equal 200, res.code.to_i
@@ -371,7 +371,7 @@ class TestServer < Testcase
       ENV["YAHNS_FD"] = @srv.fileno.to_s
       srv.start.join
     end
-    c = TCPSocket.new(host, port)
+    c = get_tcp_client(host, port)
     c.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
     buf = Timeout.timeout(10) { c.read }
     assert_match(/Connection: close/, buf)