Skip to content

Commit

Permalink
Improve test script.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Mar 25, 2013
1 parent 29d78c2 commit aafcda8
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@ LOCAL_PORT="1090"
SOCKS="127.0.0.1:$LOCAL_PORT"

test_get() {
local url
url=$1
target=$2
code=$3

if [[ -z $code ]]; then
code="200"
fi

# get 5 times
for i in {1..2}; do
# -s silent to disable progress meter, but enable --show-error
# -i to include http header
# -L to follow redirect so we should always get HTTP 200
cont=`curl --socks5 $SOCKS -s --show-error -i -L $url 2>&1`
ok=`echo $cont | grep -E -o "HTTP/1\.1 +$code"`
html=`echo $cont | grep -E -o -i "$target"`
if [[ -z $ok || -z $html ]] ; then
echo "=============================="
echo "GET $url FAILED!!!"
echo "$ok"
echo "$html"
echo $cont
echo "=============================="
return 1
fi
sleep 0.3
done
return 0
}

test_shadowsocks() {
local url
local method
local server_pid
Expand All @@ -18,27 +50,24 @@ test_get() {
local_pid=$!

# wait server and client finish startup
sleep 0.5
sleep 1

# get 5 times
for i in {1..5}; do
if ! curl -s --socks5 $SOCKS $url >/dev/null 2>&1; then
echo "=============================="
echo "GET $url $method FAILED!!!"
echo "=============================="
kill -SIGINT $server_pid
kill -SIGINT $local_pid
exit 1
if ! test_get $url "<html"; then
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
return 1
fi
done
echo "=============================="
echo "GET $url $method passed"
echo "=============================="
kill -SIGINT $server_pid
kill -SIGINT $local_pid
sleep 0.5
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
sleep 1
}

test_get baidu.com
test_get baidu.com rc4
test_shadowsocks baidu.com
test_shadowsocks baidu.com rc4

0 comments on commit aafcda8

Please sign in to comment.