From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] test/*: fix mktmpdir usage for 1.9.3
Date: Mon, 29 Feb 2016 08:18:55 +0000 [thread overview]
Message-ID: <20160229081855.20378-1-e@80x24.org> (raw)
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 ++--
| 2 +-
| 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"
--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
--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
reply other threads:[~2016-02-29 8:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160229081855.20378-1-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
http://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).