Update comment.
[beanstalkd.git] / check-one.sh
blob29617e7f6be3ffd382850b1353b15c8e3dbbf06d
1 #!/bin/sh
3 server=localhost
4 port=11400
5 tmpdir="$TMPDIR"
6 test -z "$tmpdir" && tmpdir=/tmp
7 tmpf="${tmpdir}/bnch$$"
8 nc='nc -q 1'
9 nc -q 1 2>&1 | grep -q option && nc='nc -w 1' # workaround for older netcat
11 commands="$1"; shift
12 expected="$1"; shift
14 # Allow generic tests to specify their own behavior completely.
15 test -x $commands && exec $commands
17 cleanup() {
19 test -z "$bpid" || kill -9 $bpid
20 rm -f "$tmpf"
21 } >/dev/null 2>&1
24 catch() {
25 echo '' Interrupted
26 exit 3
29 trap cleanup EXIT
30 trap catch HUP INT QUIT TERM
32 if [ ! -x ./beanstalkd ]; then
33 echo "Executable ./beanstalkd not found; do you need to compile first?"
34 exit 2
37 ./beanstalkd -p $port >/dev/null 2>/dev/null &
38 bpid=$!
40 sleep .1
41 if ! ps -p $bpid >/dev/null; then
42 echo "Could not start beanstalkd for testing, port $port is taken"
43 exit 2
46 # Run the test
47 fgrep -v "#" $commands | $nc $server $port > "$tmpf"
49 # Check the output
50 diff $expected "$tmpf"