-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathtest-grpc-interop
executable file
·120 lines (102 loc) · 4.36 KB
/
test-grpc-interop
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
# This script runs a grpc interop long-running test.
# It requires bazel build following targets:
# //test/grpc:all
# @@com_github_grpc_grpc//test/cpp/interop:interop_client
# @@com_github_grpc_grpc//test/cpp/interop:stress_test
# @@com_github_grpc_grpc//test/cpp/interop:metrics_client
#set -x
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. ${ROOT}/script/all-utilities \
|| { echo "Cannot load Bash utilities" ; exit 1 ; }
HOST=''
DURATION_IN_HOUR=0
TEST_CASES='empty_unary:10,large_unary:10,'
TEST_CASES+='empty_stream:10,client_streaming:10,ping_pong:20,server_streaming:10,'
TEST_CASES+='status_code_and_message:10,custom_metadata:10'
while getopts :h:l:t: arg; do
case ${arg} in
h) HOST="${OPTARG}";;
l) DURATION_IN_HOUR="${OPTARG}";;
t) TEST_CASES="${OPTARG}";;
*) echo "Invalid option: -${OPTARG}";;
esac
done
[[ -n "${HOST}" ]] || error_exit 'Please specify a host with -h option.'
# Waits for the proxy and backend to start.
HOST_IP=${HOST%:*}
HOST_PORT=${HOST#*:}
echo "HOST_IP: ${HOST_IP}, HOST_PORT: ${HOST_PORT}"
retry $ROOT/bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/interop_client --server_port "${HOST_PORT}" \
--server_host "${HOST_IP}" \
|| error_exit 'Failed to send one request, the proxy did not start properly.'
DURATION_IN_SEC=$((DURATION_IN_HOUR * 60 * 60))
[[ ${DURATION_IN_SEC} -gt 120 ]] || DURATION_IN_SEC=120
echo "Starts interop stress test at $(date)."
echo "Test during is: $((DURATION_IN_SEC / 60)) minutes."
echo "Test cases are: ${TEST_CASES}"
# Start a background test client job.
$ROOT/bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/stress_test \
--server_addresses "${HOST}" \
--num_channels_per_server 200 \
--num_stubs_per_channel 1 \
--test_cases "${TEST_CASES}" 2> /dev/null&
TEST_JOB=$!
trap "kill ${TEST_JOB}" EXIT
START_TIME=$(date +"%s")
END_TIME=$((START_TIME + DURATION_IN_SEC))
RUN_COUNT=0
FAIL_COUNT=0
export GRPC_GO_LOG_SEVERITY_LEVEL=INFO
detect_memory_leak_init "http://${HOST}"
while true; do
CURR_TIME=$(date +"%s")
((RUN_COUNT++))
sleep 10
METRIC_RESULT=$("$ROOT/bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/metrics_client" \
--total_only --metrics_server_address=localhost:8081 2>&1 | tail -1)
QPS=$(echo ${METRIC_RESULT}|awk '{print $NF}')
echo "Metric result: ${METRIC_RESULT}"
echo "Metric report at $((CURR_TIME - START_TIME)) seconds: ${QPS} qps"
# Count non zero QPS as success.
[[ ${QPS} -gt 100 ]] || ((FAIL_COUNT++))
# Break if test has run long enough.
[[ $(date +"%s") -lt ${END_TIME} ]] || break
done
echo "Total test count: ${RUN_COUNT}, failed count: ${FAIL_COUNT}."
# If failure time is more than %5 of total test time, mark failed.
RESULT=0
if [[ ${FAIL_COUNT} -gt $((RUN_COUNT / 20)) && ${FAIL_COUNT} -gt 1 ]] ; then
RESULT=1
fi
# We fail the test if memory increase is large.
detect_memory_leak_final && MEMORY_LEAK=0 || MEMORY_LEAK=1
unset GRPC_GO_LOG_SEVERITY_LEVEL
exit $((${RESULT} + ${MEMORY_LEAK}))