unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 7da26f8934618c72df9a7f10046c745db1a92a94 1676 bytes (raw)
$ git show v0.0.0:test/test_helper.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
# Copyright (c) 2005 Zed A. Shaw 
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors.  See http://mongrel.rubyforge.org/attributions.html 
# for more information.


HERE = File.dirname(__FILE__) unless defined?(HERE)
%w(lib ext bin test).each do |dir| 
  $LOAD_PATH.unshift "#{HERE}/../#{dir}"
end

require 'rubygems'
require 'test/unit'
require 'net/http'
require 'timeout'
require 'cgi/session'
require 'fileutils'
require 'benchmark'
require 'digest/sha1'
require 'uri'
require 'stringio'
require 'pp'

require 'mongrel'

if ENV['DEBUG']
  require 'ruby-debug'
  Debugger.start
end

def redirect_test_io
  orig_err = STDERR.dup
  orig_out = STDOUT.dup
  STDERR.reopen("test_stderr.log")
  STDOUT.reopen("test_stdout.log")

  begin
    yield
  ensure
    STDERR.reopen(orig_err)
    STDOUT.reopen(orig_out)
  end
end
    
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
  results = []
  uris.each do |u|
    res = nil

    if u.kind_of? String
      res = Net::HTTP.get(URI.parse(u))
    else
      url = URI.parse(u[0])
      res = Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
    end

    assert res != nil, "Didn't get a response: #{u}"
    results << res
  end

  return results
end

# process_based_port provides a port number, usable for TCP and UDP  
# connections based on $$ and with a 5000 as base. 
# this is required if you perform several builds of mongrel in parallel 
# (like continuous integration systems) 
def process_based_port 
  5000 + $$ % 1000 
end

git clone https://yhbt.net/unicorn.git