Skip to content

Commit 630bc33

Browse files
committed
update tests/test_find_active_server.sh
1 parent 708e7c3 commit 630bc33

File tree

1 file changed

+43
-53
lines changed

1 file changed

+43
-53
lines changed

tests/test_find_active_server.sh

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,113 +60,101 @@ if is_CI; then
6060
export TIMEOUT=30
6161
fi
6262

63-
echo "testing socket ordering result consistency"
63+
echo "testing socket ordering result consistency:"
6464
echo
6565

66-
check_output "yahoo.com" ./find_active_server.py $opts --num-threads 1 --port 80 yahoo.com google.com
66+
run_grep "^yahoo.com$" ./find_active_server.py $opts --num-threads 1 --port 80 yahoo.com google.com
6767

68-
hr
69-
echo "testing socket returns only functional server"
68+
echo "testing socket returns only functional server:"
7069
echo
7170

72-
check_output "google.com" ./find_active_server.py $opts --port 80 0.0.0.1 google.com
71+
run_grep "^google.com$" ./find_active_server.py $opts --port 80 0.0.0.1 google.com
7372

74-
hr
75-
echo "testing socket ordering result consistency with individual port overrides"
73+
echo "testing socket ordering result consistency with individual port overrides:"
7674
echo
7775

78-
check_output "yahoo.com:80" ./find_active_server.py $opts --port 1 yahoo.com:80 google.com
76+
run_grep "^yahoo.com:80$" ./find_active_server.py $opts --port 1 yahoo.com:80 google.com
7977

80-
check_output "google.com:80" ./find_active_server.py $opts --port 1 yahoo.com google.com:80
78+
run_grep "^google.com:80$" ./find_active_server.py $opts --port 1 yahoo.com google.com:80
8179

8280
# ============================================================================ #
83-
hr
84-
echo "checking --ping and --port switch conflict fails"
85-
echo
86-
./find_active_server.py $opts --ping --port 1 yahoo.com google.com
87-
check_exit_code 3
88-
echo
8981

90-
hr
91-
echo "checking --ping and --http switch conflict fails"
82+
echo "checking --ping and --port switch conflict fails:"
9283
echo
93-
./find_active_server.py $opts --ping --http yahoo.com google.com
94-
check_exit_code 3
84+
run_fail 3 ./find_active_server.py $opts --ping --port 1 yahoo.com google.com
85+
86+
echo "checking --ping and --http switch conflict fails:"
9587
echo
88+
run_fail 3 ./find_active_server.py $opts --ping --http yahoo.com google.com
9689

9790
# ============================================================================ #
98-
hr
99-
echo "testing ping returns only functional server"
91+
92+
echo "testing ping returns only functional server:"
10093
echo
101-
check_output "google.com" ./find_active_server.py $opts --ping 0.0.0.1 4.4.4.4 google.com
94+
run_grep "^google.com$" ./find_active_server.py $opts --ping 0.0.0.1 4.4.4.4 google.com
10295

103-
hr
104-
echo "testing ping returns only functional server, ignoring port override"
96+
echo "testing ping returns only functional server, ignoring port override:"
10597
echo
10698

107-
check_output "google.com" ./find_active_server.py $opts -n1 --ping 0.0.0.1 4.4.4.4 google.com:80
99+
run_grep "^google.com$" ./find_active_server.py $opts -n1 --ping 0.0.0.1 4.4.4.4 google.com:80
108100

109101
# ============================================================================ #
110-
hr
111-
echo "testing http ordering result consistency"
102+
103+
echo "testing http ordering result consistency:"
112104
echo
113105

114106
# Google's server latency is so much less than yahoo's that giving -n2 will allow google.com to overtake yahoo.com, limit to 1 so that yahoo gets the next available slot
115-
check_output "yahoo.com" ./find_active_server.py $opts -n1 --http 0.0.0.1 yahoo.com google.com
107+
run_grep "^yahoo.com$" ./find_active_server.py $opts -n1 --http 0.0.0.1 yahoo.com google.com
116108

117-
hr
118-
echo "testing https ordering result consistency"
109+
echo "testing https ordering result consistency:"
119110
echo
120111

121-
check_output "yahoo.com" ./find_active_server.py $opts -n1 --https yahoo.com google.com
112+
run_grep "^yahoo.com$" ./find_active_server.py $opts -n1 --https yahoo.com google.com
122113

123114
# there is an bug somewhere in Alpine Linux's libraries where only --https doesn't limit concurrency and the yahoo result is often faster on https, breaking this test
124115
# works fine on normal Linux distributions like Centos, Debian and Ubuntu
125-
check_output "google.com" ./find_active_server.py $opts -n1 --https 0.0.0.1 google.com yahoo.com
116+
run_grep "^google.com$" ./find_active_server.py $opts -n1 --https 0.0.0.1 google.com yahoo.com
126117

118+
echo "testing blank result for localhost 9999:"
127119
echo
128-
echo "testing blank result for localhost 9999"
129-
echo
130-
DEBUG="" check_output "" ./find_active_server.py --https localhost --port 9999 -q
120+
DEBUG="" ERRCODE=1 run_grep "^$" ./find_active_server.py --https localhost --port 9999 -q
131121

122+
echo "testing NO_AVAILABLE_SERVER for localhost 9999 verbose:"
132123
echo
133-
echo "testing NO_AVAILABLE_SERVER for localhost 9999 verbose"
134-
echo
135-
check_output "NO_AVAILABLE_SERVER" ./find_active_server.py --https localhost --port 9999
124+
ERRCODE=1 run_grep "^NO_AVAILABLE_SERVER$" ./find_active_server.py --https localhost --port 9999
136125

137126
#echo
138127
#echo "testing http returns no results when using wrong port 25"
139128
#echo
140129

141130
# DEBUG=1 breaks this to return NO_AVAILABLE_SERVER
142-
#DEBUG="" check_output "" ./find_active_server.py $opts mail.google.com --http --port 25
131+
#DEBUG="" ERRCODE=1 run_grep "^$" ./find_active_server.py $opts mail.google.com --http --port 25
143132

144133
# hangs a bit
145-
#check_output "NO_AVAILABLE_SERVER" ./find_active_server.py $opts mail.google.com --https --port 25
134+
#ERRCODE=1 run_grep "^NO_AVAILABLE_SERVER$" ./find_active_server.py $opts mail.google.com --https --port 25
146135

147-
echo
148-
echo "testing https with url path and regex matching"
136+
echo "testing https with url path and regex matching:"
149137
echo
150138

151-
check_output "github.com" ./find_active_server.py $opts --https google.com github.com -u /harisekhon --regex 'pytools'
139+
run_grep "^github.com$" ./find_active_server.py $opts --https google.com github.com -u /harisekhon --regex 'pytools'
152140

153141
# ============================================================================ #
154-
hr
155-
echo "testing HTTP regex filtering"
142+
143+
echo "testing HTTP regex filtering:"
156144
echo
157145

158-
check_output "yahoo.com" ./find_active_server.py $opts --http --regex 'yahoo' google.com yahoo.com
146+
run_grep "^yahoo.com$" ./find_active_server.py $opts --http --regex 'yahoo' google.com yahoo.com
159147

160148
# ============================================================================ #
161-
hr
162-
echo "testing HTTPS regex filtering"
149+
150+
echo "testing HTTPS regex filtering:"
163151
echo
164152

165-
check_output "yahoo.com" ./find_active_server.py $opts --https --regex '(?:yahoo)' google.com yahoo.com
153+
run_grep "^yahoo.com$" ./find_active_server.py $opts --https --regex '(?:yahoo)' google.com yahoo.com
166154

167155
# ============================================================================ #
168-
hr
169-
echo "testing random socket select 10 times contains both google and yahoo results"
156+
157+
echo "testing random socket select 10 times contains both google and yahoo results:"
170158
echo
171159

172160
# Google's servers are consistenly so much faster / lower latency that I end up with all 10 as google here, must restrict to single threaded random to allow yahoo to succeed
@@ -196,10 +184,11 @@ else
196184
die "Failed to return both google.com and yahoo.com in results from $count_socket_attempts --random runs"
197185
fi
198186
echo
187+
hr
199188

200189
# ============================================================================ #
201-
hr
202-
echo "testing random http select 10 times contains both google and yahoo results"
190+
191+
echo "testing random http select 10 times contains both google and yahoo results:"
203192
echo
204193

205194
#output="$(for x in {1..10}; do ./find_active_server.py -n1 --http --random google.com yahoo.com; done)"
@@ -229,6 +218,7 @@ if [ $found_google_http -eq 1 -a $found_yahoo_http -eq 1 ]; then
229218
else
230219
die "Failed to return both google.com and yahoo.com in results from $count_http_attempts --random runs"
231220
fi
221+
hr
232222

233223
echo
234224
echo "SUCCEEDED - all tests passed for find_active_server.py"

0 commit comments

Comments
 (0)