Run bringup and takedown for every test.
[beanstalkd.git] / check-one.sh
blobf9f6f87ad8a5df27ccadafafe2524679ebb9793f
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'
10 commands="$1"; shift
11 expected="$1"; shift
13 cleanup() {
15 test -z "$bpid" || kill -9 $bpid
16 rm -f "$tmpf"
17 } >/dev/null 2>&1
20 catch() {
21 echo '' Interrupted
22 exit 3
25 trap cleanup EXIT
26 trap catch HUP INT QUIT TERM
28 ./beanstalkd -p $port >/dev/null 2>/dev/null &
29 bpid=$!
31 sleep .1
32 if ! ps $bpid >/dev/null; then
33 echo "Could not start beanstalkd for testing, port $port is taken"
34 exit 2
37 # Run the test
38 fgrep -v "#" $commands | $nc $server $port > "$tmpf"
40 # Check the output
41 diff $expected "$tmpf"