t/test-lib.sh in rainbows-0.3.0 vs t/test-lib.sh in rainbows-0.4.0
- old
+ new
@@ -1,65 +1,23 @@
#!/bin/sh
# Copyright (c) 2009 Rainbows! developers
+. ./my-tap-lib.sh
-# pipefail is non-POSIX, but useful in ksh/bash
-(
- set +e
- set -o pipefail 2>/dev/null
-)
-if test $? -eq 0
-then
- set -o pipefail
-else
- echo >&2 "WARNING: your shell does not understand pipefail"
-fi
-
-set -e
-
-T=$(basename $0)
+set +u
if test -z "$model"
then
- case $T in
- t1???-thread-pool-*.sh) model=ThreadPool ;;
- t2???-thread-spawn-*.sh) model=ThreadSpawn ;;
- t3???-revactor-*.sh) model=Revactor ;;
- t4???-rev-*.sh) model=Rev ;;
- *) model=any ;;
- esac
+ # defaulting to Base would unfortunately fail some concurrency tests
+ model=ThreadSpawn
+ t_info "model undefined, defaulting to $model"
fi
-ruby="${ruby-'ruby'}"
-RUBY_VERSION=${RUBY_VERSION-$($ruby -e 'puts RUBY_VERSION')}
-t_pfx=$PWD/trash/$T-$RUBY_VERSION
+set -e
+RUBY="${RUBY-ruby}"
+RUBY_VERSION=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')}
+t_pfx=$PWD/trash/$model.$T-$RUBY_VERSION
set -u
-# ensure a sane environment
-TZ=UTC LC_ALL=C LANG=C
-export LANG LC_ALL TZ
-unset CDPATH
-
-die () {
- echo >&2 "$@"
- exit 1
-}
-
-_test_on_exit () {
- code=$?
- case $code in
- 0)
- echo "ok $T"
- rm -f $_TEST_OK_RM_LIST
- ;;
- *) echo "not ok $T" ;;
- esac
- rm -f $_TEST_RM_LIST
- exit $code
-}
-
-_TEST_RM_LIST=
-_TEST_OK_RM_LIST=
-trap _test_on_exit EXIT
PATH=$PWD/bin:$PATH
export PATH
test -x $PWD/bin/unused_listen || die "must be run in 't' directory"
@@ -71,16 +29,17 @@
nr=$(($nr - 1))
sleep 1
done
}
+# requires $1 and prints out the value of $2
require_check () {
lib=$1
const=$2
- if ! $ruby -r$lib -e "puts $const" >/dev/null 2>&1
+ if ! $RUBY -r$lib -e "puts $const" >/dev/null 2>&1
then
- echo >&2 "skipping $T since we don't have $lib"
+ t_info "skipping $T since we don't have $lib"
exit 0
fi
}
# given a list of variable names, create temporary files and assign
@@ -88,20 +47,26 @@
rtmpfiles () {
for id in "$@"
do
name=$id
_tmp=$t_pfx.$id
- > $_tmp
eval "$id=$_tmp"
- _TEST_OK_RM_LIST="$_TEST_OK_RM_LIST $_tmp"
case $name in
*fifo)
rm -f $_tmp
mkfifo $_tmp
- _TEST_RM_LIST="$_TEST_RM_LIST $_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 () {
@@ -122,9 +87,55 @@
then
die "SIGKILL found in $_r_err"
fi
}
+# rainbows_setup [ MODEL [ WORKER_CONNECTIONS ] ]
+rainbows_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"
+
+# close my-tap-lib.sh FDs
+unless ENV['UNICORN_FD']
+ IO.for_fd(3).close rescue nil
+ IO.for_fd(4).close rescue nil
+end
+
+before_fork do |server, worker|
+ # test script will block while reading from $fifo,
+ # so notify the script on the first worker we spawn
+ # by opening the FIFO
+ if worker.nr == 0
+ File.open("$fifo", "wb").close
+ end
+end
+EOF
+ {
+ if test $# -ge 1
+ then
+ echo 'Rainbows! do'
+ echo " use :$1"
+ test $# -eq 2 && echo " worker_connections $2"
+ echo end
+ else
+ echo "Rainbows! { use :$model }"
+ fi
+ } >> $unicorn_config
+}
+
+rainbows_wait_start () {
+ # "cat $fifo" will block until the before_fork hook is called in
+ # the Unicorn config file
+ test x = x"$(cat $fifo)"
+ rainbows_pid=$(cat $pid)
+}
+
case $model in
Rev) require_check rev Rev::VERSION ;;
Revactor) require_check revactor Revactor::VERSION ;;
+EventMachine) require_check eventmachine EventMachine::VERSION ;;
esac