]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Unit test for tcp request reorder and timeouts.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 21 Jan 2019 13:04:08 +0000 (13:04 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 21 Jan 2019 13:04:08 +0000 (13:04 +0000)
git-svn-id: file:///svn/unbound/trunk@5041 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testdata/tcp_req_timeout.tdir/tcp_req_timeout.conf [new file with mode: 0644]
testdata/tcp_req_timeout.tdir/tcp_req_timeout.dsc [new file with mode: 0644]
testdata/tcp_req_timeout.tdir/tcp_req_timeout.post [new file with mode: 0644]
testdata/tcp_req_timeout.tdir/tcp_req_timeout.pre [new file with mode: 0644]
testdata/tcp_req_timeout.tdir/tcp_req_timeout.test [new file with mode: 0644]
testdata/tcp_req_timeout.tdir/tcp_req_timeout.testns [new file with mode: 0644]

index 58c196b5ae710ecfced7399276225bb82d715534..19da4259498cee6e6b5a8b5b5d756e8dde2c9739 100644 (file)
@@ -1,5 +1,6 @@
 21 January 2018: Wouter
        - Fix tcp idle timeout test, for difference in the tcp reply code.
+       - Unit test for tcp request reorder and timeouts.
 
 17 January 2018: Wouter
        - For caps-for-id fallback, use the whitelist to avoid timeout
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.conf b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.conf
new file mode 100644 (file)
index 0000000..45db9e1
--- /dev/null
@@ -0,0 +1,22 @@
+server:
+       verbosity: 2
+       # num-threads: 1
+       interface: 127.0.0.1
+       port: @PORT@
+       use-syslog: no
+       directory: .
+       pidfile: "unbound.pid"
+       chroot: ""
+       username: ""
+       do-not-query-localhost: no
+
+       local-zone: "example.net" static
+       local-data: "www1.example.net. IN A 1.2.3.1"
+       local-data: "www2.example.net. IN A 1.2.3.2"
+       local-data: "www3.example.net. IN A 1.2.3.3"
+       tcp-idle-timeout: 2000
+       local-zone: "drop.net" deny
+
+forward-zone:
+       name: "."
+       forward-addr: "127.0.0.1@@TOPORT@"
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.dsc b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.dsc
new file mode 100644 (file)
index 0000000..fc61155
--- /dev/null
@@ -0,0 +1,16 @@
+BaseName: tcp_req_order
+Version: 1.0
+Description: Test tcp request order timeouts.
+CreationDate: Mon Jan 21 11:23:00 CET 2018
+Maintainer: Wouter Wijngaards
+Category: 
+Component:
+CmdDepends: 
+Depends: 
+Help:
+Pre: tcp_req_order.pre
+Post: tcp_req_order.post
+Test: tcp_req_order.test
+AuxFiles: 
+Passed:
+Failure:
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.post b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.post
new file mode 100644 (file)
index 0000000..7e83092
--- /dev/null
@@ -0,0 +1,12 @@
+# #-- tcp_req_timeout.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 $FWD_PID
+kill_pid $UNBOUND_PID
+cat fwd.log
+cat unbound.log
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.pre b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.pre
new file mode 100644 (file)
index 0000000..d6cfe97
--- /dev/null
@@ -0,0 +1,31 @@
+# #-- tcp_req_timeout.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
+
+. ../common.sh
+get_random_port 2
+UNBOUND_PORT=$RND_PORT
+FWD_PORT=$(($RND_PORT + 1))
+echo "UNBOUND_PORT=$UNBOUND_PORT" >> .tpkg.var.test
+echo "FWD_PORT=$FWD_PORT" >> .tpkg.var.test
+
+# start forwarder
+get_ldns_testns
+$LDNS_TESTNS -p $FWD_PORT tcp_req_timeout.testns >fwd.log 2>&1 &
+FWD_PID=$!
+echo "FWD_PID=$FWD_PID" >> .tpkg.var.test
+
+# make config file
+sed -e 's/@PORT\@/'$UNBOUND_PORT'/' -e 's/@TOPORT\@/'$FWD_PORT'/' < tcp_req_timeout.conf > ub.conf
+# start unbound in the background
+PRE="../.."
+$PRE/unbound -vvvv -d -c ub.conf >unbound.log 2>&1 &
+UNBOUND_PID=$!
+echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
+
+cat .tpkg.var.test
+wait_ldns_testns_up fwd.log
+wait_unbound_up unbound.log
+
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.test b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.test
new file mode 100644 (file)
index 0000000..831f8a8
--- /dev/null
@@ -0,0 +1,136 @@
+# #-- tcp_req_timeout.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)
+# check what sort of netcat we have
+if nc -h 2>&1 | grep "q secs"; then
+        ncopt="-q 3 -i 4"
+else
+        ncopt="-i 4"
+fi
+
+# this test query should just work (server is up)
+echo "> query www1.example.net."
+$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www1.example.net. A IN >outfile 2>&1
+cat outfile
+if test "$?" -ne 0; then
+       echo "exit status not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+if grep "www1.example.net" outfile | grep "1.2.3.1"; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+echo "OK"
+
+# multiple requests that are answered immediately and then the timeout
+echo "> query www1.example.net. www2.example.net. www3.example.net. www.example.com."
+$PRE/streamtcp -a -f 127.0.0.1@$UNBOUND_PORT www1.example.net. A IN www2.example.net A IN www3.example.net A IN www.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 fwd.log 
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+if grep "www1.example.net" outfile | grep "1.2.3.1"; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+if grep "www2.example.net" outfile | grep "1.2.3.2"; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+if grep "www3.example.net" outfile | grep "1.2.3.3"; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+if grep "stream closed" outfile; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+
+# multiple requests that are waiting for answers and then the timeout
+echo "> query www2.example.com. www2.example.com. www3.example.com."
+$PRE/streamtcp -a -f 127.0.0.1@$UNBOUND_PORT www2.example.com. A IN www2.example.com A IN www3.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 fwd.log 
+       cat unbound.log
+       echo "Not OK"
+       exit 1
+fi
+if grep "stream closed" outfile; then
+       echo "content OK"
+else
+       echo "result contents not OK"
+       echo "> cat logfiles"
+       cat outfile
+       cat fwd.log 
+       cat unbound.log
+       echo "result contents not OK"
+       exit 1
+fi
+
+# wait a bit
+sleep 2
+
+# echo a couple requests to the other side and then wait for the timeout.
+# this creates waiting answers in the reply queue.
+echo "> nc www.example.net www2.example.net www3.example.net"
+( echo "0021eb410100000100000000000003777777076578616d706c65036e657400000100010022eb41010000010000000000000477777732076578616d706c65036e657400000100010022eb41010000010000000000000477777733076578616d706c65036e65740000010001" | xxd -r -p ; sleep 10 ; echo "") | nc $ncopt 127.0.0.1 $UNBOUND_PORT | xxd | tee outfile
+
+echo "OK"
+exit 0
diff --git a/testdata/tcp_req_timeout.tdir/tcp_req_timeout.testns b/testdata/tcp_req_timeout.tdir/tcp_req_timeout.testns
new file mode 100644 (file)
index 0000000..6946009
--- /dev/null
@@ -0,0 +1,63 @@
+; nameserver test file
+$ORIGIN example.com.
+$TTL 3600
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=4
+SECTION QUESTION
+www    IN      A
+SECTION ANSWER
+www    IN      A       10.20.30.40
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=4
+SECTION QUESTION
+www2   IN      A
+SECTION ANSWER
+www2   IN      A       10.20.30.42
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=4
+SECTION QUESTION
+www3   IN      A
+SECTION ANSWER
+www3   IN      A       10.20.30.43
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=2
+SECTION QUESTION
+www4   IN      A
+SECTION ANSWER
+www4   IN      A       10.20.30.44
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=2
+SECTION QUESTION
+www5   IN      A
+SECTION ANSWER
+www5   IN      A       10.20.30.45
+ENTRY_END
+
+ENTRY_BEGIN
+MATCH opcode qtype qname
+REPLY QR AA NOERROR
+ADJUST copy_id sleep=2
+SECTION QUESTION
+www6   IN      A
+SECTION ANSWER
+www6   IN      A       10.20.30.46
+ENTRY_END