Sha256: 3be24b9e5dba19b15b56f73890611746b85c48322569ba355b5c69e1ea3346a5

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# -*- encoding: binary -*-
$stderr.sync = $stdout.sync = true
Thread.abort_on_exception = true
require "test/unit"
require "digest/sha1"
require "stringio"
require "tmpdir"
require "socket"
require "rack"
require "tempfile"
$-w = true
require "http_spew"

def start_server(config, worker_processes = 4, rewindable_input = false)
  ENV["RACK_ENV"] = "deployment"
  addr = ENV["TEST_HOST"] || "127.0.0.1"
  sock = TCPServer.new(addr, 0)
  port = sock.addr[1]
  fifo = Tempfile.new("fifo")
  fifo_path = fifo.path
  fifo.close!
  system("mkfifo", fifo_path) or abort "mkfifo: #$?"
  cfg = Tempfile.new("unicorn.config")
  cfg.puts "worker_processes #{worker_processes}"
  cfg.puts "preload_app true"
  cfg.puts "rewindable_input #{rewindable_input}"
  cfg.puts <<EOF
after_fork do |s,w|
  w.nr == (s.worker_processes - 1) and File.open("#{fifo_path}", "w").close
end
EOF
  cfg.flush
  pid = fork do
    ENV["UNICORN_FD"] = sock.fileno.to_s
    exec "unicorn", "-l#{addr}:#{port}", "-c#{cfg.path}", config
  end
  File.open(fifo_path).close
  File.unlink fifo_path
  [ addr, port, pid ]
end

def rand_data(nr)
  File.open("/dev/urandom", "rb") { |fp| fp.read(nr) }
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
http_spew-0.4.1 test/helper.rb
http_spew-0.4.0 test/helper.rb
http_spew-0.3.0 test/helper.rb
http_spew-0.2.0 test/helper.rb