Skip to content
This repository was archived by the owner on Apr 9, 2020. It is now read-only.

Commit b51b1ba

Browse files
committed
Use netcat to wait server start.
1 parent 83788b0 commit b51b1ba

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

script/test.sh

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
#!/bin/bash
22

3+
# Use [ -n "$TRAVIS" ] to test for running on Travis-CI.
4+
35
# Run in the scripts directory.
46
cd "$( dirname "${BASH_SOURCE[0]}" )"
57

6-
OPTION="-p 8389 -k foobar"
78
LOCAL_PORT="1090"
9+
SERVER_PORT="8389"
10+
OPTION="-p $SERVER_PORT -k foobar"
811
SOCKS="127.0.0.1:$LOCAL_PORT"
912
HTTP_PORT="8123"
1013

14+
wait_server() {
15+
local port
16+
port=$1
17+
for i in {1..20}; do
18+
# sleep first because this maybe called immediately after server start
19+
sleep 0.1
20+
nc -z -w 4 127.0.0.1 $port && break
21+
done
22+
}
23+
1124
start_http_server() {
1225
go build http.go
1326
./http $HTTP_PORT &
27+
wait_server $HTTP_PORT
1428
http_pid=$!
1529
}
1630

@@ -20,6 +34,8 @@ stop_http_server() {
2034

2135
test_get() {
2236
local url
37+
local target
38+
local code
2339
url=$1
2440
target=$2
2541
code=$3
@@ -56,24 +72,11 @@ test_shadowsocks() {
5672

5773
$SERVER $OPTION -m "$method" &
5874
server_pid=$!
75+
wait_server $SERVER_PORT
76+
5977
$LOCAL $OPTION -s 127.0.0.1 -l $LOCAL_PORT -m "$method" &
6078
local_pid=$!
61-
62-
# Wait server and client finish startup.
63-
sleeptime=0.1
64-
if [ -n "$TRAVIS" ]; then
65-
# On Travis we need to wait a little longer.
66-
sleeptime=1
67-
elif echo $SERVER $LOCAL | grep 'py'; then
68-
# The python version is slow to start.
69-
if [[ $method == "table" ]]; then
70-
sleeptime=2
71-
else
72-
sleeptime=0.5
73-
fi
74-
fi
75-
echo $sleeptime
76-
sleep $sleeptime
79+
wait_server $LOCAL_PORT
7780

7881
for i in {1..3}; do
7982
if ! test_get $url "shadowsocks-go"; then

0 commit comments

Comments
 (0)