Hi,
I'm sending a patch to improve the test shell scripts as follows:
- accept connections only from localhost
- retry binding a different port if 11400 is not available (unlikely, I know,
but still)
- cleanup fiu fifos in /tmp
I understand that these are not important from an upstream perspective, but
they definitely are for enabling tests during unsupervised builds.
Please also consider either fixing or dropping the pause-tubes test (currently
failing due to an obsolete .expected file)
Cheers,
Serafeim
--
debtags-organised WNPP bugs: http://members.hellug.gr/serzan/wnpp
--
You received this message because you are subscribed to the Google Groups
"beanstalk-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/beanstalk-talk?hl=en.
--- beanstalkd-1.4.3.orig/check-one.sh
+++ beanstalkd-1.4.3/check-one.sh
@@ -1,7 +1,8 @@
-#!/bin/sh
+#!/bin/bash
+
+. sh-tests/common.functions
server=localhost
-port=11400
tmpdir="$TMPDIR"
test -z "$tmpdir" && tmpdir=/tmp
tmpf="${tmpdir}/bnch$$"
@@ -34,14 +35,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-./beanstalkd -p $port >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing, port $port is taken"
- exit 2
-fi
+start_beanstalkd
# Run the test
fgrep -v "#" $commands | $nc $server $port > "$tmpf"
--- beanstalkd-1.4.3.orig/sh-tests/binlog-diskfull-delete.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-diskfull-delete.sh
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
ENOSPC=28
server=localhost
-port=11400
tmpdir="$TMPDIR"
size=1000
test -z "$tmpdir" && tmpdir=/tmp
@@ -25,17 +26,9 @@ fail() {
exit 1
}
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
- rm -rf "$logdir" "$out1" "$out2"
+ rm -rf "$logdir" "$out1" "$out2" ${tmpdir}/fiu-ctrl-[0-9]*.{in,out}
}
catch() {
@@ -56,16 +49,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-fiu-run -x ./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir "-s $size" "fiu-run -x"
# Insert enough jobs to create another binlog file
$nc $server $port <<EOF > "$out1"
@@ -181,15 +165,7 @@ test "$res" -eq 0 || exit $res
killbeanstalkd
-sleep .1
-./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir "-s $size"
$nc $server $port <<EOF > "$out2"
delete 8
--- beanstalkd-1.4.3.orig/sh-tests/binlog-diskfull.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-diskfull.sh
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
ENOSPC=28
server=localhost
-port=11400
tmpdir="$TMPDIR"
size=1000
test -z "$tmpdir" && tmpdir=/tmp
@@ -18,17 +19,9 @@ then
exit 0
fi
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
- rm -rf "$logdir" "$out1" "$out2"
+ rm -rf "$logdir" "$out1" "$out2" ${tmpdir}/fiu-ctrl-[0-9]*.{in,out}
}
catch() {
@@ -44,16 +37,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-fiu-run -x ./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir "-s $size" "fiu-run -x"
# Make beanstalkd think the disk is full now.
fiu-ctrl -e posix/io/oc/open -i $ENOSPC $bpid
@@ -114,14 +98,7 @@ test "$res" -eq 0 || exit $res
killbeanstalkd
sleep .1
-./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir "-s $size"
$nc $server $port <<EOF > "$out2"
delete 1
--- beanstalkd-1.4.3.orig/sh-tests/binlog-basic.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-basic.sh
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
server=localhost
-port=11400
tmpdir="$TMPDIR"
test -z "$tmpdir" && tmpdir=/tmp
out1="${tmpdir}/bnch$$.1"
@@ -10,14 +11,6 @@ logdir="${tmpdir}/bnch$$.d"
nc='nc -q 1'
nc -q 1 2>&1 | grep -q "illegal option" && nc='nc -w 1' # workaround for older netcat
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
rm -rf "$logdir" "$out1" "$out2"
@@ -36,16 +29,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir
$nc $server $port <<EOF > "$out1"
put 0 0 100 0
@@ -62,14 +46,7 @@ test "$res" -eq 0 || exit $res
killbeanstalkd
sleep .1
-./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir
$nc $server $port <<EOF > "$out2"
delete 1
--- beanstalkd-1.4.3.orig/sh-tests/binlog-sizelimit.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-sizelimit.sh
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
server=localhost
-port=11400
tmpdir="$TMPDIR"
size=1024
truncated_size_1=796
@@ -20,14 +21,6 @@ fail() {
exit 1
}
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
rm -rf "$logdir" "$out1" "$out2"
@@ -51,16 +44,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir "-s $size"
# Check that the first binlog file is the proper size.
test "$(fsize "$logdir"/binlog.1)" -eq $size || fail first binlog wrong size
--- beanstalkd-1.4.3.orig/sh-tests/binlog-bury.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-bury.sh
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
server=localhost
-port=11400
tmpdir="$TMPDIR"
test -z "$tmpdir" && tmpdir=/tmp
out1="${tmpdir}/bnch$$.1"
@@ -10,14 +11,6 @@ logdir="${tmpdir}/bnch$$.d"
nc='nc -q 1'
nc -q 1 2>&1 | grep -q "illegal option" && nc='nc -w 1' # workaround for older netcat
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
rm -rf "$logdir" "$out1" "$out2"
@@ -36,16 +29,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir
$nc $server $port <<EOF > "$out1"
put 0 0 100 0
--- beanstalkd-1.4.3.orig/sh-tests/binlog-read.sh
+++ beanstalkd-1.4.3/sh-tests/binlog-read.sh
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
+. sh-tests/common.functions
+
server=localhost
-port=11400
tmpdir="$TMPDIR"
test -z "$tmpdir" && tmpdir=/tmp
out1="${tmpdir}/bnch$$.1"
@@ -10,14 +11,6 @@ logdir="${tmpdir}/bnch$$.d"
nc='nc -q 1'
nc -q 1 2>&1 | grep -q "illegal option" && nc='nc -w 1' # workaround for older netcat
-killbeanstalkd() {
- {
- test -z "$bpid" || kill -9 $bpid
- /bin/true # Somehow this gets rid of an unnessary shell message.
- } >/dev/null 2>&1
- bpid=
-}
-
cleanup() {
killbeanstalkd
rm -rf "$logdir" "$out1" "$out2"
@@ -36,16 +29,7 @@ if [ ! -x ./beanstalkd ]; then
exit 2
fi
-mkdir -p $logdir
-
-./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir
$nc $server $port <<EOF > "$out1"
use test
@@ -79,14 +63,7 @@ test "$res" -eq 0 || exit $res
killbeanstalkd
sleep 1
-./beanstalkd -p $port -b "$logdir" >/dev/null 2>/dev/null &
-bpid=$!
-
-sleep .1
-if ! ps -p $bpid >/dev/null; then
- echo "Could not start beanstalkd for testing (possibly port $port is taken)"
- exit 2
-fi
+start_beanstalkd $logdir
$nc $server $port <<EOF > "$out2"
watch test
--- /dev/null
+++ beanstalkd-1.4.3/sh-tests/common.functions
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+start_port=11400
+max_port_retries=20
+
+function killbeanstalkd() {
+ {
+ test -z "$bpid" || kill -9 $bpid
+ /bin/true # Somehow this gets rid of an unnessary shell message.
+ } >/dev/null 2>&1
+}
+
+function start_beanstalkd {
+ port=$start_port
+ logdir="$1"
+ other_args="$2" # other_args and fiu are optional
+ fiu="$3"
+
+ if [ "x$logdir" != "x" ]; then
+ mkdir -p $logdir
+ other_args="-b $logdir $other_args"
+ fi
+
+ max_port=$(($port + $max_port_retries))
+ while [ $port -lt $max_port ]; do
+ $fiu ./beanstalkd -l 127.0.0.1 -p $port $other_args >/dev/null 2>/dev/null &
+ bpid=$!
+
+ sleep .1
+ if ! ps -p $bpid >/dev/null; then
+ echo "Could not start beanstalkd for testing (possibly port $port is taken)" >&2
+ port=$(($port + 1))
+ else
+ echo "Started beanstalkd (pid: $bpid), listening on port $port"
+ export port bpid
+ return
+ fi
+ done
+ echo "Giving up after having tried $max_port_retries different ports" >&2
+ exit 2
+}