support for Rack hijack in request and response
[unicorn.git] / t / test-lib.sh
blob79791112dedae35bd8c6b3b4eb9214ff4616b526
1 #!/bin/sh
2 # Copyright (c) 2009 Rainbows! hackers
3 # Copyright (c) 2010 Unicorn hackers
4 . ./my-tap-lib.sh
6 set +u
8 # sometimes we rely on http_proxy to avoid wasting bandwidth with Isolate
9 # and multiple Ruby versions
10 NO_PROXY=${UNICORN_TEST_ADDR-127.0.0.1}
11 export NO_PROXY
13 set -e
14 RUBY="${RUBY-ruby}"
15 RUBY_VERSION=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')}
16 RUBY_ENGINE=${RUBY_ENGINE-$($RUBY -e 'puts((RUBY_ENGINE rescue "ruby"))')}
17 t_pfx=$PWD/trash/$T-$RUBY_ENGINE-$RUBY_VERSION
18 set -u
20 PATH=$PWD/bin:$PATH
21 export PATH
23 test -x $PWD/bin/unused_listen || die "must be run in 't' directory"
25 wait_for_pid () {
26 path="$1"
27 nr=30
28 while ! test -s "$path" && test $nr -gt 0
30 nr=$(($nr - 1))
31 sleep 1
32 done
35 # given a list of variable names, create temporary files and assign
36 # the pathnames to those variables
37 rtmpfiles () {
38 for id in "$@"
40 name=$id
42 case $name in
43 *fifo)
44 _tmp=$t_pfx.$id
45 eval "$id=$_tmp"
46 rm -f $_tmp
47 mkfifo $_tmp
48 T_RM_LIST="$T_RM_LIST $_tmp"
50 *socket)
51 _tmp="$(mktemp -t $id.$$.XXXXXXXX)"
52 if test $(printf "$_tmp" |wc -c) -gt 108
53 then
54 echo >&2 "$_tmp too long, tests may fail"
55 echo >&2 "Try to set TMPDIR to a shorter path"
57 eval "$id=$_tmp"
58 rm -f $_tmp
59 T_RM_LIST="$T_RM_LIST $_tmp"
62 _tmp=$t_pfx.$id
63 eval "$id=$_tmp"
64 > $_tmp
65 T_OK_RM_LIST="$T_OK_RM_LIST $_tmp"
67 esac
68 done
71 dbgcat () {
72 id=$1
73 eval '_file=$'$id
74 echo "==> $id <=="
75 sed -e "s/^/$id:/" < $_file
78 check_stderr () {
79 set +u
80 _r_err=${1-${r_err}}
81 set -u
82 if grep -v $T $_r_err | grep -i Error
83 then
84 die "Errors found in $_r_err"
85 elif grep SIGKILL $_r_err
86 then
87 die "SIGKILL found in $_r_err"
91 # unicorn_setup
92 unicorn_setup () {
93 eval $(unused_listen)
94 port=$(expr $listen : '[^:]*:\([0-9]\+\)')
95 host=$(expr $listen : '\([^:]*\):[0-9]\+')
97 rtmpfiles unicorn_config pid r_err r_out fifo tmp ok
98 cat > $unicorn_config <<EOF
99 listen "$listen"
100 pid "$pid"
101 stderr_path "$r_err"
102 stdout_path "$r_out"
106 unicorn_wait_start () {
107 # no need to play tricks with FIFOs since we got "ready_pipe" now
108 unicorn_pid=$(cat $pid)
111 rsha1 () {
112 sha1sum.rb