unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: unicorn-public@bogomips.org
Cc: Simon Eskildsen <simon.eskildsen@shopify.com>
Subject: [PATCH] test_ccc: use a pipe to synchronize test
Date: Thu, 23 Mar 2017 00:05:50 +0000	[thread overview]
Message-ID: <20170323000550.GA7541@starla> (raw)

Sleeping 1 second to test 100 requests is too long for some
systems; and not long enough for others.

We need to also finish reading the sleeper response to ensure
the server actually got the second request in, before sending
SIGQUIT to terminate it; as it's possible for the test client
to connect and abort 100 clients before the server even
increments the request counter for the 2nd request.
 Btw, ccc-tcp-v3 is merged to master, and I guess
 5.3.0rc1 is coming soon.

 test/unit/test_ccc.rb | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/test/unit/test_ccc.rb b/test/unit/test_ccc.rb
index 22b1a9c..0db0c38 100644
--- a/test/unit/test_ccc.rb
+++ b/test/unit/test_ccc.rb
@@ -12,7 +12,9 @@ def test_ccc_tcpi
     port = srv.addr[1]
     err = Tempfile.new('unicorn_ccc')
     rd, wr = IO.pipe
+    sleep_pipe = IO.pipe
     pid = fork do
+      sleep_pipe[1].close
       reqs = 0
       worker_pid = nil
@@ -22,7 +24,10 @@ def test_ccc_tcpi
         reqs += 1
-        sleep(1) if env['PATH_INFO'] == '/sleep'
+        # will wake up when writer closes
+        sleep_pipe[0].read if env['PATH_INFO'] == '/sleep'
         [ 200, [ %w(Content-Length 0),  %w(Content-Type text/plain) ], [] ]
       ENV['UNICORN_FD'] = srv.fileno.to_s
@@ -57,6 +62,10 @@ def test_ccc_tcpi
                    "Host: example.com\r\n\r\n")
+    sleep_pipe[1].close # wake up the reader in the worker
+    res = sleeper.read
+    assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first sleeper response'
+    assert_match %r{\r\n\r\n\z}, res, 'got end of sleeper response'
     kpid = pid
     pid = nil

                 reply	other threads:[~2017-03-23  0:05 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:

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170323000550.GA7541@starla \
    --to=e@80x24.org \
    --cc=simon.eskildsen@shopify.com \
    --cc=unicorn-public@bogomips.org \


* 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


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).