forked from easegress-io/easegress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·82 lines (71 loc) · 2.59 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Copyright (c) 2017, MegaEase
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Test the Easegress' basic functionality which is generating
# an HTTPServer and Pipeline for testing HTTP Requests.
set -e
# path related define.
# Note: use $(dirname $(realpath ${BASH_SOURCE[0]})) to value SCRIPTPATH is OK in linux platform,
# but not in MacOS.(cause there is not `realpath` in it)
# reference: https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
pushd $SCRIPTPATH"/../../example" > /dev/null
EXAMPLEDIR="$SCRIPTPATH"/../../example
PRIMARYDIR=$EXAMPLEDIR"/primary-single"
EGCTL=$PRIMARYDIR"/bin/egctl"
EGBUILDER=$PRIMARYDIR"/bin/egbuilder"
# target file related define.
server="primary-single/bin/easegress-server"
eg_apiport=12381
# color define.
COLOR_NONE='\033[0m'
COLOR_INFO='\033[0;36m'
COLOR_ERROR='\033[1;31m'
# clean cleans primary-single's data and cluster data and the `go run` process.
function clean()
{
# basic cleaning routine
bash $EXAMPLEDIR/stop_cluster.sh
bash $EXAMPLEDIR/clean_cluster.sh
}
# clean the cluster resource first.
clean
# start primary-single for testing.
bash $PRIMARYDIR/start.sh
try_time=0
# wait Easegress to be ready, it will retry three times.
# reference: https://unix.stackexchange.com/questions/5277/how-do-i-tell-a-script-to-wait-for-a-process-to-start-accepting-requests-on-a-po
while ! nc -z localhost $eg_apiport </dev/null
do
sleep 5
try_time=$(($try_time+1))
if [[ $try_time -ge 3 ]]; then
echo -e "\n{COLOR_ERROR}start test server $server failed${COLOR_NONE}"
exit 1
fi
done
# check the primary-single running status
pid=`ps -eo pid,args | grep "$server" | grep -v grep | awk '{print $1}'`
if [ "$pid" = "" ]; then
echo -e "\n${COLOR_ERROR}start test server $server failed${COLOR_NONE}"
clean
exit 2
else
echo -e "\n${COLOR_INFO}start test server $server ok${COLOR_NONE}"
fi
# run go test
env EGCTL=$EGCTL EGBUILDER=$EGBUILDER go test -v $SCRIPTPATH
popd > /dev/null
exit 0