diff --git a/script/http.go b/script/http.go new file mode 100644 index 0000000..6ae6f4d --- /dev/null +++ b/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 ") + os.Exit(1) + } + http.HandleFunc("/", handler) + http.ListenAndServe("127.0.0.1:"+os.Args[1], nil) +} diff --git a/script/test.sh b/script/test.sh index 8481927..307c4b4 100755 --- a/script/test.sh +++ b/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 @@ -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 "