# #-- tcp_conn_limit_dec.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


# Set unbound to limit all IPv4 addresses to 0 connections.
# Make sure TCP connection fails.


if uname | grep MINGW >/dev/null; then
	echo "no job control in shell on windows. end test"
	exit 0
fi

PRE="../.."
. ../common.sh
get_make
(cd $PRE; $MAKE streamtcp)

# after first three queries, the counter must decrement to answer the others.
for i in 1 2 3 4 5 6 7 8; do
	echo
	echo "> query www$i.example.net."
	$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www$i.example.net. A IN 2>&1 | tee outfile
	if test "$?" -ne 0; then
		echo "exit status not OK"
		echo "Not OK"
		exit 1
	else
		echo "exit status OK"
	fi
	if grep "10.20.30.4$i" outfile; then
		echo "OK"
	else
		echo "not OK"
		exit 1
	fi
done

exit 0
