TEST_DESCRIPTION="Testing interruption from within a function."
. ./test_header.sh

slptst() {
    if [ $1 = "k" ] ; then
	echo Interrupting.
	prll_interrupt
    else
	echo Sleeping $1 seconds.
	sleep $1
	echo Slept $1 seconds.
    fi
}

attempts=0
while [ $attempts -lt 5 ] ; do
    PRLL_NRJOBS=3 prll -b slptst 5 1 2 k 4 3 | \
	diff -q interrupt.dat - && break
    echo "Test failed, but that means nothing unless it"
    echo "fails consistently. Retrying."
    attempts=$((attempts + 1))
done
if [ $attempts -ge 5 ] ; then
    echo "Test seems to fail consistently."
    exit 1
fi
