diff options
Diffstat (limited to 'test/test_helper.rb')
-rw-r--r-- | test/test_helper.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb index 787adbf..3bdbeb1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# -*- encoding: binary -*- + # Copyright (c) 2005 Zed A. Shaw # You can redistribute it and/or modify it under the same terms as Ruby. # @@ -27,7 +29,7 @@ require 'tempfile' require 'fileutils' require 'logger' require 'unicorn' -require 'unicorn/http11' +require 'unicorn_http' if ENV['DEBUG'] require 'ruby-debug' @@ -102,6 +104,10 @@ def unused_port(addr = '127.0.0.1') begin begin port = base + rand(32768 - base) + while port == Unicorn::Const::DEFAULT_PORT + port = base + rand(32768 - base) + end + sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) sock.bind(Socket.pack_sockaddr_in(port, addr)) sock.listen(5) @@ -139,7 +145,7 @@ def retry_hit(uris = []) tries = DEFAULT_TRIES begin hit(uris) - rescue Errno::ECONNREFUSED => err + rescue Errno::EINVAL, Errno::ECONNREFUSED => err if (tries -= 1) > 0 sleep DEFAULT_RES retry @@ -262,3 +268,29 @@ def wait_for_death(pid) end raise "PID:#{pid} never died!" end + +# executes +cmd+ and chunks its STDOUT +def chunked_spawn(stdout, *cmd) + fork { + crd, cwr = IO.pipe + crd.binmode + cwr.binmode + crd.sync = cwr.sync = true + + pid = fork { + STDOUT.reopen(cwr) + crd.close + cwr.close + exec(*cmd) + } + cwr.close + begin + buf = crd.readpartial(16384) + stdout.write("#{'%x' % buf.size}\r\n#{buf}") + rescue EOFError + stdout.write("0\r\n") + pid, status = Process.waitpid(pid) + exit status.exitstatus + end while true + } +end |