Skip to content

Commit

Permalink
Use shadowsocks-py to test compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Sep 21, 2014
1 parent dd6f7da commit 3ffa3a1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
21 changes: 21 additions & 0 deletions script/http.go
@@ -0,0 +1,21 @@
/* Simple http server for testing. */
package main

import (
"fmt"
"net/http"
"os"
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, shadowsocks-go!")
}

func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: http <port>")
os.Exit(1)
}
http.HandleFunc("/", handler)
http.ListenAndServe("127.0.0.1:"+os.Args[1], nil)
}
66 changes: 44 additions & 22 deletions script/test.sh
@@ -1,8 +1,22 @@
#!/bin/bash

# Run in the scripts directory.
cd "$( dirname "${BASH_SOURCE[0]}" )"

OPTION="-p 8389 -k foobar"
LOCAL_PORT="1090"
SOCKS="127.0.0.1:$LOCAL_PORT"
HTTP_PORT="8123"

start_http_server() {
go build http.go
./http $HTTP_PORT &
http_pid=$!
}

stop_http_server() {
kill -SIGTERM $http_pid
}

test_get() {
local url
Expand Down Expand Up @@ -45,23 +59,32 @@ test_shadowsocks() {
$LOCAL $OPTION -s 127.0.0.1 -l $LOCAL_PORT -m "$method" &
local_pid=$!

# wait server and client finish startup
sleep 1
# Wait server and client finish startup.
sleeptime=0.1
if echo $SERVER $LOCAL | grep 'py'; then
# The python version is slow to start.
if [[ $method == "table" ]]; then
sleeptime=2
else
sleeptime=0.5
fi
fi
sleep $sleeptime

for i in {1..3}; do
if ! test_get $url "<html"; then
if ! test_get $url "shadowsocks-go"; then
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
stop_http_server
exit 1
fi
sleep 0.3
done
echo "=============================="
echo "GET $url $method passed"
echo "=============================="
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
sleep 1
sleep 0.1
}

test_server_local_pair() {
Expand All @@ -70,33 +93,32 @@ test_server_local_pair() {
echo "============================================================"

local url
if [[ -z "$TRAVIS" ]]; then
url="www.baidu.com"
else
# on travis
url="www.google.com"
fi
test_shadowsocks baidu.com table
test_shadowsocks baidu.com rc4
test_shadowsocks baidu.com aes-128-cfb
test_shadowsocks baidu.com aes-192-cfb
test_shadowsocks baidu.com aes-256-cfb
test_shadowsocks baidu.com bf-cfb
test_shadowsocks baidu.com des-cfb
test_shadowsocks baidu.com cast5-cfb
url=http://127.0.0.1:$HTTP_PORT/README.md
test_shadowsocks $url table
test_shadowsocks $url rc4
test_shadowsocks $url rc4-md5
test_shadowsocks $url aes-128-cfb
test_shadowsocks $url aes-192-cfb
test_shadowsocks $url aes-256-cfb
test_shadowsocks $url bf-cfb
test_shadowsocks $url des-cfb
test_shadowsocks $url cast5-cfb
}

start_http_server

SERVER="shadowsocks-server"
LOCAL="shadowsocks-local"
test_server_local_pair

if [[ -n $SS_NODEJS ]]; then
SERVER="ssserver"
if [[ -n $SS_PYTHON ]]; then
SERVER="$SS_PYTHON/server.py"
LOCAL="shadowsocks-local"
test_server_local_pair

SERVER="shadowsocks-server"
LOCAL="sslocal"
LOCAL="$SS_PYTHON/local.py"
test_server_local_pair
fi

stop_http_server

0 comments on commit 3ffa3a1

Please sign in to comment.