test-util.sh 1.11 KB
Newer Older
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
#
# General test script utilities
#

TMPDIR=/dev/shm
export TMPDIR
mkdir -p $TMPDIR
TMPBASE=$(mktemp --tmpdir -d test-XXXXXX)

echo "tmpbase: $TMPBASE"

if [ ! -d $TMPBASE ];
then
  echo "Temp directory doesn't exist: $TMPBASE"
  exit 3
fi

function run_to ()
{
    maxtime=${1}s
    shift
    timeout --signal=9 $maxtime "$@"
}

function test_start_servers ()
{
    nservers=${1:-4}
    startwait=${2:-15}
29
    maxtime=${3:-120}
30 31

    # start daemons
32
    for i in `seq $nservers`
33
    do
34
        src/bake-bulk-mkpool -s 100M $TMPBASE/svr-$i.dat
35 36 37 38
        if [ $? -ne 0 ]; then
            exit 1
        fi

39
        run_to ${maxtime} src/bake-bulk-server-daemon -f $TMPBASE/svr-$i.addr na+sm $TMPBASE/svr-$i.dat &
40 41 42 43 44 45 46 47 48 49 50 51
        if [ $? -ne 0 ]; then
            # TODO: this doesn't actually work; can't check return code of
            # something executing in background.  We have to rely on the
            # return codes of the actual client side tests to tell if
            # everything started properly
            exit 1
        fi
    done

    # wait for servers to start
    sleep ${startwait}

52
    svr1=`cat $TMPBASE/svr-1.addr`
53
}