# #-- pymod_thread.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test

PRE="../.."
if grep "define WITH_PYTHONMODULE 1" $PRE/config.h; then
	echo "have python module"
else
	echo "no python module"
	exit 0
fi

if test "`uname 2>&1`" = "Darwin"; then
        ldnsdir=`grep ldnsdir= ../../Makefile | sed -e 's/ldnsdir=//'`
        echo export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$ldnsdir/lib:../../.libs"
        export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$ldnsdir/lib:../../.libs"
fi

# see if config file verifies
if $PRE/unbound-checkconf ub.conf; then
	echo "checkconf OK"
else
	echo "checkconf failed"
	exit 1
fi

# do the test
# generate some load.
echo "> dig www[1-10].example.com."
dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile1 &
dig @localhost -p $UNBOUND_PORT www2.example.com. | tee outfile3 &
dig @localhost -p $UNBOUND_PORT www3.example.com. | tee outfile2 &
dig @localhost -p $UNBOUND_PORT www4.example.com. | tee outfile4 &
dig @localhost -p $UNBOUND_PORT www5.example.com. | tee outfile5 &
dig @localhost -p $UNBOUND_PORT www6.example.com. | tee outfile6 &
dig @localhost -p $UNBOUND_PORT www7.example.com. | tee outfile7 &
dig @localhost -p $UNBOUND_PORT www8.example.com. | tee outfile8 &
dig @localhost -p $UNBOUND_PORT www9.example.com. | tee outfile9 &
dig @localhost -p $UNBOUND_PORT www10.example.com. | tee outfile10 &

wait  # wait for all jobs to complete.

echo "> cat logfiles"
cat fwd.log 
cat unbound.log
echo "> check answer"
for x in outfile1 outfile2 outfile3 outfile4 outfile5; do
if grep "192.168.1.1" $x; then
	echo "$x OK"
else
	echo "$x Not OK"
	exit 1
fi
done

for x in outfile6 outfile7 outfile8 outfile9 outfile10; do
if grep "192.168.1.1" $x; then
	echo "$x OK"
else
	echo "$x Not OK"
	exit 1
fi
done

exit 0
