aboutsummaryrefslogtreecommitdiff
path: root/testdata/tcp_req_timeout.tdir/tcp_req_timeout.test
blob: 831f8a854cbb8154cd0ba998243a447e3d5fb709 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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