File: test.sh

package info (click to toggle)
webdis 0.1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 564 kB
  • ctags: 798
  • sloc: ansic: 5,240; sh: 254; python: 247; makefile: 93
file content (78 lines) | stat: -rwxr-xr-x 2,134 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# This script runs redis server and webdis server and launches the test
# suite. It avoids race condition while obtaining a port to listen by
# binding to random available port. The port is then found via netstat -nlp
# using PID-file.

TMPDIR=`mktemp -d`

WEBDIS_PIDFILE=${TMPDIR}/webdis.pid
WEBDIS_CONFFILE=${TMPDIR}/webdis.json
WEBDIS_LOGFILE=${TMPDIR}/webdis.log

REDIS_CONFFILE=${TMPDIR}/redis.conf
REDIS_PIDFILE=${TMPDIR}/redis.pid
REDIS_SOCK=${TMPDIR}/redis.sock

if [ -n "$WEBDIS_BIN" ] ; then
    if [ ! -x "$WEBDIS_BIN" ] ; then
        echo "webdis binary $WEBDIS_BIN is not executable" 
        exit 1
    fi
else
    WEBDIS_BIN="$PWD/webdis"
fi

set_up() {
    echo "Generating config files.."
	sed -e "s|REDIS_SOCK|${REDIS_SOCK}|" -e "s|WEBDIS_PIDFILE|${WEBDIS_PIDFILE}|" \
        -e "s|WEBDIS_LOGFILE|${WEBDIS_LOGFILE}|" \
        debian/webdis-test.json > ${WEBDIS_CONFFILE}
	sed -e "s|REDIS_PIDFILE|${REDIS_PIDFILE}|" -e "s|REDIS_SOCK|${REDIS_SOCK}|" \
        debian/redis-test.conf > ${REDIS_CONFFILE}

    echo "Starting redis-server.."
	/sbin/start-stop-daemon --start --verbose \
		--pidfile ${REDIS_PIDFILE} \
		--exec `which redis-server` -- ${REDIS_CONFFILE} || return 1

    echo "Starting webdis.."
	/sbin/start-stop-daemon --start --verbose \
		--pidfile ${WEBDIS_PIDFILE} \
		--exec $WEBDIS_BIN -- ${WEBDIS_CONFFILE} || return 2

    WEBDIS_PID=`cat $WEBDIS_PIDFILE`
    export WEBDIS_PORT=`grep -o 'listening on port.*$' ${WEBDIS_LOGFILE}| \
        tail -1|cut -d " " -f 4`
    [ "0$WEBDIS_PORT" -gt 0 ] || return 3
    echo webdis is listening on port "$WEBDIS_PORT"
}

tear_down() {
    echo "Shutting down webdis.."
	/sbin/start-stop-daemon --stop --verbose \
		--retry=TERM/1/KILL/1 \
		--pidfile ${WEBDIS_PIDFILE} \
		--name webdis
    echo "Shutting down redis-server.."
	/sbin/start-stop-daemon --stop --verbose \
		--retry=TERM/1/KILL/1 \
		--pidfile ${REDIS_PIDFILE} \
		--name redis-server
}

if ! set_up ; then
    echo "Setting up redis/webdis server FAILED."
    tear_down
    exit 1
fi

echo Running test commands: $*

$*
EXIT_CODE=$?

tear_down
rm -fR $TMPDIR

exit $EXIT_CODE