From: W.C.A. Wijngaards Date: Wed, 3 Jun 2020 08:01:51 +0000 (+0200) Subject: add test for tcp reuse X-Git-Tag: release-1.13.0rc1~5^2~80 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7b4606702986cc06d65887f65dc12664c58ef27d;p=thirdparty%2Funbound.git add test for tcp reuse --- diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.conf b/testdata/tcp_reuse.tdir/tcp_reuse.conf new file mode 100644 index 000000000..e8de8d3f8 --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.conf @@ -0,0 +1,17 @@ +server: + verbosity: 5 + # num-threads: 1 + interface: 127.0.0.1 + port: @PORT@ + use-syslog: no + directory: . + pidfile: "unbound.pid" + chroot: "" + username: "" + do-not-query-localhost: no + + tcp-upstream: yes + +forward-zone: + name: "." + forward-addr: "127.0.0.1@@TOPORT@" diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.conf2 b/testdata/tcp_reuse.tdir/tcp_reuse.conf2 new file mode 100644 index 000000000..308107094 --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.conf2 @@ -0,0 +1,29 @@ +# this is the upstream server that has pipelining and responds to queries. +server: + verbosity: 1 + # num-threads: 1 + interface: 127.0.0.1 + port: @PORT@ + use-syslog: no + directory: . + pidfile: "unbound2.pid" + chroot: "" + username: "" + do-not-query-localhost: no + + log-queries: yes + log-replies: yes + log-identity: "upstream" + + local-zone: "." refuse + local-zone: "example.com" static + local-data: "www.example.com A 10.20.30.40" + local-data: "www1.example.com A 10.20.30.41" + local-data: "www2.example.com A 10.20.30.42" + local-data: "www3.example.com A 10.20.30.43" + local-data: "www4.example.com A 10.20.30.44" + +# if queries escape, send them to localhost +forward-zone: + name: "." + forward-addr: "127.0.0.1@@TOPORT@" diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.dsc b/testdata/tcp_reuse.tdir/tcp_reuse.dsc new file mode 100644 index 000000000..8a780480d --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.dsc @@ -0,0 +1,16 @@ +BaseName: tcp_reuse +Version: 1.0 +Description: Test tcp stream reuse. +CreationDate: Wed Jun 03 09:37:00 CET 2020 +Maintainer: Wouter Wijngaards +Category: +Component: +CmdDepends: +Depends: +Help: +Pre: tcp_reuse.pre +Post: tcp_reuse.post +Test: tcp_reuse.test +AuxFiles: +Passed: +Failure: diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.post b/testdata/tcp_reuse.tdir/tcp_reuse.post new file mode 100644 index 000000000..7399d3603 --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.post @@ -0,0 +1,18 @@ +# #-- tcp_reuse.post --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# source the test var file when it's there +[ -f .tpkg.var.test ] && source .tpkg.var.test +# +# do your teardown here +. ../common.sh +kill_pid $UPSTREAM_PID +kill_pid $UNBOUND_PID +if test -f unbound2.log; then + echo ">>> upstream log" + cat unbound2.log +fi +if test -f unbound.log; then + echo ">>> unbound log" + cat unbound.log +fi diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.pre b/testdata/tcp_reuse.tdir/tcp_reuse.pre new file mode 100644 index 000000000..511dbc6f7 --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.pre @@ -0,0 +1,34 @@ +# #-- tcp_reuse.pre--# +# 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="../.." +. ../common.sh +get_random_port 2 +UNBOUND_PORT=$RND_PORT +UPSTREAM_PORT=$(($RND_PORT + 1)) +echo "UNBOUND_PORT=$UNBOUND_PORT" >> .tpkg.var.test +echo "UPSTREAM_PORT=$UPSTREAM_PORT" >> .tpkg.var.test + +# make config file +sed -e 's/@PORT\@/'$UNBOUND_PORT'/' -e 's/@TOPORT\@/'$UPSTREAM_PORT'/' < tcp_reuse.conf > ub.conf +# start unbound in the background +#$PRE/unbound -d -c ub.conf >unbound.log 2>&1 & +$PRE/unbound -d -c ub.conf 2>&1 | tee unbound.log & +UNBOUND_PID=$! +echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test +wait_unbound_up unbound.log + +# make upstream config file +sed -e 's/@PORT\@/'$UPSTREAM_PORT'/' -e 's/@TOPORT\@/'$UPSTREAM_PORT'/' < tcp_reuse.conf2 > ub2.conf +# start upstream unbound in the background +#$PRE/unbound -d -c ub2.conf >unbound2.log 2>&1 & +$PRE/unbound -d -c ub2.conf 2>&1 | tee unbound2.log & +UPSTREAM_PID=$! +echo "UPSTREAM_PID=$UPSTREAM_PID" >> .tpkg.var.test +wait_unbound_up unbound2.log + +cat .tpkg.var.test + diff --git a/testdata/tcp_reuse.tdir/tcp_reuse.test b/testdata/tcp_reuse.tdir/tcp_reuse.test new file mode 100644 index 000000000..4b006afc4 --- /dev/null +++ b/testdata/tcp_reuse.tdir/tcp_reuse.test @@ -0,0 +1,65 @@ +# #-- tcp_reuse.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="../.." +. ../common.sh + +get_make +(cd $PRE; $MAKE streamtcp) + +echo "> query www1.example.com." +$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www1.example.com. A IN >outfile 2>&1 +cat outfile +if test "$?" -ne 0; then + echo "exit status not OK" + echo "> cat logfiles" + cat outfile + cat unbound2.log + cat unbound.log + echo "Not OK" + exit 1 +fi +if grep "www1.example.com" outfile | grep "10.20.30.41"; then + echo "content OK" +else + echo "result contents not OK" + echo "> cat logfiles" + cat outfile + cat unbound2.log + cat unbound.log + echo "result contents not OK" + exit 1 +fi +echo "OK" +echo "" + +# this should be reused on the same tcp stream: +echo "> query www2.example.com." +$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www2.example.com. A IN >outfile 2>&1 +cat outfile +if test "$?" -ne 0; then + echo "exit status not OK" + echo "> cat logfiles" + cat outfile + cat unbound2.log + cat unbound.log + echo "Not OK" + exit 1 +fi +if grep "www2.example.com" outfile | grep "10.20.30.42"; then + echo "content OK" +else + echo "result contents not OK" + echo "> cat logfiles" + cat outfile + cat unbound2.log + cat unbound.log + echo "result contents not OK" + exit 1 +fi + +echo "OK" +exit 0