yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 1/5] test_proxy_pass_no_buffering: fix racy test
Date: Tue,  7 Jun 2016 07:39:04 +0000	[thread overview]
Message-ID: <20160607073908.31035-2-e@80x24.org> (raw)
In-Reply-To: <20160607073908.31035-1-e@80x24.org>

We can force output buffer files to a directory of our
choosing to avoid being confused by temporary files
from other tests polluting the process we care about.
---
 test/test_proxy_pass_no_buffering.rb | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/test/test_proxy_pass_no_buffering.rb b/test/test_proxy_pass_no_buffering.rb
index b2c8b48..c60ccad 100644
--- a/test/test_proxy_pass_no_buffering.rb
+++ b/test/test_proxy_pass_no_buffering.rb
@@ -35,11 +35,13 @@ def setup
     server_helper_setup
     skip "kcar missing yahns/proxy_pass" unless defined?(Kcar)
     require 'yahns/proxy_pass'
+    @tmpdir = yahns_mktmpdir
   end
 
   def teardown
     @srv2.close if defined?(@srv2) && !@srv2.closed?
     server_helper_teardown
+    FileUtils.rm_rf(@tmpdir) if defined?(@tmpdir)
   end
 
   def check_headers(io)
@@ -55,11 +57,15 @@ def test_proxy_pass_no_buffering
     host2, port2 = @srv2.addr[3], @srv2.addr[1]
     pxp = Yahns::ProxyPass.new("http://#{host2}:#{port2}",
                                proxy_buffering: false)
+    tmpdir = @tmpdir
     pid = mkserver(cfg) do
       ObjectSpace.each_object(Yahns::TmpIO) { |io| io.close unless io.closed? }
       @srv2.close
       cfg.instance_eval do
-        app(:rack, pxp) { listen "#{host}:#{port}" }
+        app(:rack, pxp) do
+          listen "#{host}:#{port}"
+          output_buffering true, tmpdir: tmpdir
+        end
         stderr_path err.path
       end
     end
@@ -85,10 +91,11 @@ def test_proxy_pass_no_buffering
       sleep 0.1
       # ensure no files get created
       if RUBY_PLATFORM =~ /\blinux\b/ && `which lsof 2>/dev/null`.size >= 4
+        qtmpdir = Regexp.quote("#@tmpdir/")
         deleted1 = `lsof -p #{pid}`.split("\n")
-        deleted1 = deleted1.grep(/\bREG\b.* \(deleted\)/)
+        deleted1 = deleted1.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
         deleted2 = `lsof -p #{pid2}`.split("\n")
-        deleted2 = deleted2.grep(/\bREG\b.* \(deleted\)/)
+        deleted2 = deleted2.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
         [ deleted1, deleted2 ].each do |ary|
           ary.delete_if { |x| x =~ /\.(?:err|out) \(deleted\)/ }
         end

  reply	other threads:[~2016-06-07  7:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07  7:39 [PATCH \0/5] another round of proxy-related bugfixes! Eric Wong
2016-06-07  7:39 ` Eric Wong [this message]
2016-06-07  7:39 ` [PATCH 2/5] queue_*: check for closed IO objects Eric Wong
2016-06-07  7:39 ` [PATCH 3/5] cleanup graceful shutdown handling Eric Wong
2016-06-07  7:39 ` [PATCH 4/5] proxy_pass: more descriptive error messages Eric Wong
2016-06-07  7:39 ` [PATCH 5/5] proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering Eric Wong

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: https://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=20160607073908.31035-2-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

	https://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).