diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-02-17 18:53:52 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-02-17 18:53:52 -0800 |
commit | 5cef71dc6c640db414c41f59a5016fd3f5326bf9 (patch) | |
tree | 500cd48b0d92ba8b847ce6839d6889d5304fa11b /t/test-lib.sh | |
parent | 13598f977ec3b707bd1a8f2abb99825cb8f85b58 (diff) | |
download | unicorn-5cef71dc6c640db414c41f59a5016fd3f5326bf9.tar.gz |
Diffstat (limited to 't/test-lib.sh')
-rw-r--r-- | t/test-lib.sh | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh new file mode 100644 index 0000000..60ace97 --- /dev/null +++ b/t/test-lib.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# Copyright (c) 2009 Rainbows! hackers +# Copyright (c) 2010 Unicorn hackers +. ./my-tap-lib.sh + +set +u +set -e +RUBY="${RUBY-ruby}" +RUBY_VERSION=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')} +t_pfx=$PWD/trash/$T-$RUBY_VERSION +set -u + +PATH=$PWD/bin:$PATH +export PATH + +test -x $PWD/bin/unused_listen || die "must be run in 't' directory" + +wait_for_pid () { + path="$1" + nr=30 + while ! test -s "$path" && test $nr -gt 0 + do + nr=$(($nr - 1)) + sleep 1 + done +} + +# given a list of variable names, create temporary files and assign +# the pathnames to those variables +rtmpfiles () { + for id in "$@" + do + name=$id + _tmp=$t_pfx.$id + eval "$id=$_tmp" + + case $name in + *fifo) + rm -f $_tmp + mkfifo $_tmp + T_RM_LIST="$T_RM_LIST $_tmp" + ;; + *socket) + rm -f $_tmp + T_RM_LIST="$T_RM_LIST $_tmp" + ;; + *) + > $_tmp + T_OK_RM_LIST="$T_OK_RM_LIST $_tmp" + ;; + esac + done +} + +dbgcat () { + id=$1 + eval '_file=$'$id + echo "==> $id <==" + sed -e "s/^/$id:/" < $_file +} + +check_stderr () { + set +u + _r_err=${1-${r_err}} + set -u + if grep -i Error $_r_err + then + die "Errors found in $_r_err" + elif grep SIGKILL $_r_err + then + die "SIGKILL found in $_r_err" + fi +} + +# unicorn_setup +unicorn_setup () { + eval $(unused_listen) + rtmpfiles unicorn_config pid r_err r_out fifo tmp ok + cat > $unicorn_config <<EOF +listen "$listen" +pid "$pid" +stderr_path "$r_err" +stdout_path "$r_out" +EOF +} + +unicorn_wait_start () { + # no need to play tricks with FIFOs since we got "ready_pipe" now + unicorn_pid=$(cat $pid) +} + +rsha1 () { + _cmd="$(which sha1sum 2>/dev/null || :)" + test -n "$_cmd" || _cmd="$(which openssl 2>/dev/null || :) sha1" + test "$_cmd" != " sha1" || _cmd="$(which gsha1sum 2>/dev/null || :)" + + # last resort, see comments in sha1sum.rb for reasoning + test -n "$_cmd" || _cmd=sha1sum.rb + expr "$($_cmd < random_blob)" : '\([a-f0-9]\{40\}\)' +} |