Placate all the compilers. Ugly.
[beanstalkd.git] / sh-tests / binlog-read.sh
blob46d7d6fc61eefc8150047ed86f643fa3c35ec22f
1 #!/usr/bin/env bash
3 server=localhost
4 port=11400
5 tmpdir="$TMPDIR"
6 test -z "$tmpdir" && tmpdir=/tmp
7 out1="${tmpdir}/bnch$$.1"
8 out2="${tmpdir}/bnch$$.2"
9 logdir="${tmpdir}/bnch$$.d"
10 nc='nc -q 1'
11 nc -q 1 2>&1 | grep -q "illegal option" && nc='nc -w 1' # workaround for older netcat
13 killbeanstalkd() {
15 test -z "$bpid" || kill -9 $bpid
16 /bin/true # Somehow this gets rid of an unnessary shell message.
17 } >/dev/null 2>&1
18 bpid=
21 cleanup() {
22 killbeanstalkd
23 rm -rf "$logdir" "$out1" "$out2"
26 catch() {
27 echo '' Interrupted
28 exit 3
31 trap cleanup EXIT
32 trap catch HUP INT QUIT TERM
34 if [ ! -x ./beanstalkd ]; then
35 echo "Executable ./beanstalkd not found; do you need to compile first?"
36 exit 2
39 mkdir -p $logdir
41 ./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
42 bpid=$!
44 sleep .1
45 if ! ps -p $bpid >/dev/null; then
46 echo "Could not start beanstalkd for testing (possibly port $port is taken)"
47 exit 2
50 $nc $server $port <<EOF > "$out1"
51 use test
52 put 0 0 120 4
53 test
54 put 0 0 120 4
55 tes1
56 watch test
57 reserve
58 release 1 1 1
59 reserve
60 delete 2
61 quit
62 EOF
64 diff - "$out1" <<EOF
65 USING test
66 INSERTED 1
67 INSERTED 2
68 WATCHING 2
69 RESERVED 1 4
70 test
71 RELEASED
72 RESERVED 2 4
73 tes1
74 DELETED
75 EOF
76 res=$?
77 test "$res" -eq 0 || exit $res
79 killbeanstalkd
81 sleep 1
82 ./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
83 bpid=$!
85 sleep .1
86 if ! ps -p $bpid >/dev/null; then
87 echo "Could not start beanstalkd for testing (possibly port $port is taken)"
88 exit 2
91 $nc $server $port <<EOF > "$out2"
92 watch test
93 reserve
94 delete 1
95 delete 2
96 EOF
98 diff - "$out2" <<EOF
99 WATCHING 2
100 RESERVED 1 4
101 test
102 DELETED
103 NOT_FOUND