xref: /netbsd-src/external/bsd/unbound/dist/testdata/tcp_req_timeout.tdir/tcp_req_timeout.test (revision f42d8de7d1744f0ae38eedac13b4320e5351d1d6)
1# #-- tcp_req_timeout.test --#
2# source the master var file when it's there
3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
4# use .tpkg.var.test for in test variable passing
5[ -f .tpkg.var.test ] && source .tpkg.var.test
6
7PRE="../.."
8. ../common.sh
9get_make
10(cd $PRE; $MAKE streamtcp)
11# check what sort of netcat we have
12if nc -h 2>&1 | grep "q secs"; then
13        ncopt="-q 3 -i 4"
14else
15        ncopt="-i 4"
16fi
17
18# this test query should just work (server is up)
19echo "> query www1.example.net."
20$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www1.example.net. A IN >outfile 2>&1
21cat outfile
22if test "$?" -ne 0; then
23	echo "exit status not OK"
24	echo "> cat logfiles"
25	cat outfile
26	cat fwd.log
27	cat unbound.log
28	echo "Not OK"
29	exit 1
30fi
31if grep "www1.example.net" outfile | grep "1.2.3.1"; then
32	echo "content OK"
33else
34	echo "result contents not OK"
35	echo "> cat logfiles"
36	cat outfile
37	cat fwd.log
38	cat unbound.log
39	echo "result contents not OK"
40	exit 1
41fi
42echo "OK"
43
44# multiple requests that are answered immediately and then the timeout
45echo "> query www1.example.net. www2.example.net. www3.example.net. www.example.com."
46$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
47cat outfile
48if test "$?" -ne 0; then
49	echo "exit status not OK"
50	echo "> cat logfiles"
51	cat outfile
52	cat fwd.log
53	cat unbound.log
54	echo "Not OK"
55	exit 1
56fi
57if grep "www1.example.net" outfile | grep "1.2.3.1"; then
58	echo "content OK"
59else
60	echo "result contents not OK"
61	echo "> cat logfiles"
62	cat outfile
63	cat fwd.log
64	cat unbound.log
65	echo "result contents not OK"
66	exit 1
67fi
68if grep "www2.example.net" outfile | grep "1.2.3.2"; then
69	echo "content OK"
70else
71	echo "result contents not OK"
72	echo "> cat logfiles"
73	cat outfile
74	cat fwd.log
75	cat unbound.log
76	echo "result contents not OK"
77	exit 1
78fi
79if grep "www3.example.net" outfile | grep "1.2.3.3"; then
80	echo "content OK"
81else
82	echo "result contents not OK"
83	echo "> cat logfiles"
84	cat outfile
85	cat fwd.log
86	cat unbound.log
87	echo "result contents not OK"
88	exit 1
89fi
90if grep "stream closed" outfile; then
91	echo "content OK"
92else
93	echo "result contents not OK"
94	echo "> cat logfiles"
95	cat outfile
96	cat fwd.log
97	cat unbound.log
98	echo "result contents not OK"
99	exit 1
100fi
101
102# multiple requests that are waiting for answers and then the timeout
103echo "> query www2.example.com. www2.example.com. www3.example.com."
104$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
105cat outfile
106if test "$?" -ne 0; then
107	echo "exit status not OK"
108	echo "> cat logfiles"
109	cat outfile
110	cat fwd.log
111	cat unbound.log
112	echo "Not OK"
113	exit 1
114fi
115if grep "stream closed" outfile; then
116	echo "content OK"
117else
118	echo "result contents not OK"
119	echo "> cat logfiles"
120	cat outfile
121	cat fwd.log
122	cat unbound.log
123	echo "result contents not OK"
124	exit 1
125fi
126
127# wait a bit
128sleep 2
129
130# echo a couple requests to the other side and then wait for the timeout.
131# this creates waiting answers in the reply queue.
132echo "> nc www.example.net www2.example.net www3.example.net"
133( echo "0021eb410100000100000000000003777777076578616d706c65036e657400000100010022eb41010000010000000000000477777732076578616d706c65036e657400000100010022eb41010000010000000000000477777733076578616d706c65036e65740000010001" | xxd -r -p ; sleep 10 ; echo "") | nc $ncopt 127.0.0.1 $UNBOUND_PORT | xxd | tee outfile
134
135echo "OK"
136exit 0
137