yahns Ruby server user/dev discussion
 help / color / Atom feed
* [PATCH] test/*: fix mktmpdir usage for 1.9.3
@ 2016-02-29  8:18 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-02-29  8:18 UTC (permalink / raw)
  To: yahns-public

We should not infinite loop, oops :x
Also, ensure 'yahns' is in the directory in case tests are
SIGKILL-ed and directories are left over.
---
 test/helper.rb                      | 30 ++++++++++++++++--------------
 test/test_bin.rb                    |  2 +-
 test/test_buffer_tmpdir.rb          |  2 +-
 test/test_config.rb                 |  4 ++--
 test/test_extras_autoindex.rb       |  2 +-
 test/test_extras_try_gzip_static.rb |  2 +-
 test/test_proxy_pass.rb             |  2 +-
 test/test_serve_static.rb           |  8 ++++----
 test/test_server.rb                 |  8 ++++----
 test/test_unix_socket.rb            |  4 ++--
 10 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/test/helper.rb b/test/helper.rb
index 8f70ddc..73cde51 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -88,21 +88,23 @@ def __covmerge
 
 require "tempfile"
 require 'tmpdir'
-class Dir
-  def Dir.mktmpdir
-    begin
-      d = "#{Dir.tmpdir}/#$$.#{rand}"
-      Dir.mkdir(d)
-    rescue Errno::EEXIST
-    end while true
-    return d unless block_given?
-    begin
-      yield d
-    ensure
-      FileUtils.remove_entry(d)
-    end
+
+# Can't rely on mktmpdir until we drop Ruby 1.9.3 support
+def yahns_mktmpdir
+  d = nil
+  begin
+    dir = "#{Dir.tmpdir}/yahns.#$$.#{rand}"
+    Dir.mkdir(dir)
+    d = dir
+  rescue Errno::EEXIST
+  end until d
+  return d unless block_given?
+  begin
+    yield d
+  ensure
+    FileUtils.remove_entry(d)
   end
-end unless Dir.respond_to?(:mktmpdir)
+end
 
 def tmpfile(*args)
   tmp = Tempfile.new(*args)
diff --git a/test/test_bin.rb b/test/test_bin.rb
index eeaf126..be1c024 100644
--- a/test/test_bin.rb
+++ b/test/test_bin.rb
@@ -149,7 +149,7 @@ def test_usr2_nopreload_worker; usr2(false, true); end
   def test_usr2_nopreload_noworker; usr2(false, false); end
 
   def usr2(preload, worker)
-    Dir.mktmpdir { |tmpdir| usr2_dir(tmpdir, preload, worker) }
+    yahns_mktmpdir { |tmpdir| usr2_dir(tmpdir, preload, worker) }
   end
 
   def usr2_dir(tmpdir, preload, worker)
diff --git a/test/test_buffer_tmpdir.rb b/test/test_buffer_tmpdir.rb
index 6b15f9a..bac8017 100644
--- a/test/test_buffer_tmpdir.rb
+++ b/test/test_buffer_tmpdir.rb
@@ -16,7 +16,7 @@ def setup
     rescue
       skip "test needs inotify"
     end
-    @tmpdir = Dir.mktmpdir
+    @tmpdir = yahns_mktmpdir
     server_helper_setup
   end
 
diff --git a/test/test_config.rb b/test/test_config.rb
index 022f128..73d9456 100644
--- a/test/test_config.rb
+++ b/test/test_config.rb
@@ -14,7 +14,7 @@ def test_initialize
 
   def test_multi_conf_example
     pid = fork do
-      tmpdir = Dir.mktmpdir
+      tmpdir = yahns_mktmpdir
 
       # modify the example config file for testing
       path = "examples/yahns_multi.conf.rb"
@@ -38,7 +38,7 @@ def test_multi_conf_example
 
   def test_rack_basic_conf_example
     pid = fork do
-      tmpdir = Dir.mktmpdir
+      tmpdir = yahns_mktmpdir
 
       # modify the example config file for testing
       path = "examples/yahns_rack_basic.conf.rb"
diff --git a/test/test_extras_autoindex.rb b/test/test_extras_autoindex.rb
index 30d454c..fe753d5 100644
--- a/test/test_extras_autoindex.rb
+++ b/test/test_extras_autoindex.rb
@@ -10,7 +10,7 @@ class TestExtrasAutoindex < Testcase
   include ServerHelper
 
   def setup
-    @tmpdir = Dir.mktmpdir
+    @tmpdir = yahns_mktmpdir
     server_helper_setup
     skip 'Ruby 2.x required' unless ''.respond_to?(:b)
   end
diff --git a/test/test_extras_try_gzip_static.rb b/test/test_extras_try_gzip_static.rb
index 4a73764..c6c8cef 100644
--- a/test/test_extras_try_gzip_static.rb
+++ b/test/test_extras_try_gzip_static.rb
@@ -11,7 +11,7 @@ class TestExtrasTryGzipStatic < Testcase
   GPL_TEXT = IO.binread("COPYING").freeze
 
   def setup
-    @tmpdir = Dir.mktmpdir
+    @tmpdir = yahns_mktmpdir
     server_helper_setup
     skip 'Ruby 2.x required' unless ''.respond_to?(:b)
   end
diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb
index f6e0efd..448e480 100644
--- a/test/test_proxy_pass.rb
+++ b/test/test_proxy_pass.rb
@@ -177,7 +177,7 @@ def teardown
   end
 
   def test_unix_socket_no_path
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     unix_path = "#{tmpdir}/proxy_pass.sock"
     unix_srv = UNIXServer.new(unix_path)
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
diff --git a/test/test_serve_static.rb b/test/test_serve_static.rb
index 12932d2..68e84f7 100644
--- a/test/test_serve_static.rb
+++ b/test/test_serve_static.rb
@@ -10,7 +10,7 @@ class TestServeStatic < Testcase
   alias teardown server_helper_teardown
 
   def test_serve_static
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     sock = "#{tmpdir}/sock"
     err = @err
     cfg = Yahns::Config.new
@@ -120,7 +120,7 @@ def close
   end
 
   def test_aborted_sendfile_closes_opened_path
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     mksparse(tmpdir)
     fifo = "#{tmpdir}/to_path--close"
     assert system("mkfifo", fifo), "mkfifo"
@@ -147,7 +147,7 @@ def test_aborted_sendfile_closes_opened_path
   end
 
   def test_truncated_sendfile
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     size, sparse = mksparse(tmpdir)
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
     pid = mkserver(cfg) do
@@ -169,7 +169,7 @@ def test_truncated_sendfile
   end
 
   def test_expanded_sendfile
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     size, sparse = mksparse(tmpdir)
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
     pid = mkserver(cfg) do
diff --git a/test/test_server.rb b/test/test_server.rb
index 87193e3..9f33b42 100644
--- a/test/test_server.rb
+++ b/test/test_server.rb
@@ -179,7 +179,7 @@ def trailer(btype, delay = false)
   end
 
   def test_check_client_connection
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     sock = "#{tmpdir}/sock"
     unix_srv = UNIXServer.new(sock)
     unix_srv.close_on_exec = true
@@ -511,7 +511,7 @@ def test_mp_hooks_worker_nr
   end
 
   def test_pidfile_usr2
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     pidf = "#{tmpdir}/pid"
     old = "#{pidf}.oldbin"
     err = @err
@@ -635,7 +635,7 @@ def test_working_directory
     ru = lambda { |_|
       [ 200, {'Content-Length'=>Dir.pwd.size.to_s }, [Dir.pwd] ]
     }
-    Dir.mktmpdir do |tmpdir|
+    yahns_mktmpdir do |tmpdir|
       begin
         pid = mkserver(cfg) do
           $LOAD_PATH << File.expand_path("lib")
@@ -656,7 +656,7 @@ def test_working_directory
   end
 
   def test_errors
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     sock = "#{tmpdir}/sock"
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
     re = tmpfile(%w(rack .errors))
diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb
index 3911619..7b821e3 100644
--- a/test/test_unix_socket.rb
+++ b/test/test_unix_socket.rb
@@ -23,7 +23,7 @@ def unix_socket(path)
   end
 
   def test_socket
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     err, cfg = @err, Yahns::Config.new
     sock = "#{tmpdir}/sock"
     cfg.instance_eval do
@@ -48,7 +48,7 @@ def test_socket
   end
 
   def test_socket_perms
-    tmpdir = Dir.mktmpdir
+    tmpdir = yahns_mktmpdir
     err, cfg = @err, Yahns::Config.new
     sock = "#{tmpdir}/sock"
     cfg.instance_eval do
-- 
EW


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-29  8:18 [PATCH] test/*: fix mktmpdir usage for 1.9.3 Eric Wong

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox