forked from grpc/grpc-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·113 lines (88 loc) · 2.84 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·113 lines (88 loc) · 2.84 KB
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
#!/usr/bin/env bash
set -eu
set -o pipefail
# the go client does not support passing an argument with multiple test cases
# so we loop over this array calling the binary each time around
TEST_CASES=(
"empty_unary"
"large_unary"
"client_streaming"
"server_streaming"
"ping_pong"
"empty_stream"
"status_code_and_message"
"special_status_message"
"custom_metadata"
"unimplemented_method"
"unimplemented_service"
)
# join all test cases in one comma separated string (dropping the first one)
# so we can call the rust client only once, reducing the noise
JOINED_TEST_CASES=$(printf ",%s" "${TEST_CASES[@]}")
JOINED_TEST_CASES="${JOINED_TEST_CASES:1}"
set -x
echo "Running for OS: ${OSTYPE}"
case "$OSTYPE" in
darwin*) OS="darwin"; EXT="" ;;
linux*) OS="linux"; EXT="" ;;
msys*) OS="windows"; EXT=".exe" ;;
*) exit 2 ;;
esac
ARG="${1:-""}"
(cd interop && cargo build --bins)
SERVER="interop/bin/server_${OS}_amd64${EXT}"
TLS_CA="interop/data/ca.pem"
TLS_CRT="interop/data/server1.pem"
TLS_KEY="interop/data/server1.key"
# run the test server
./"${SERVER}" "${ARG}" --tls_cert_file $TLS_CRT --tls_key_file $TLS_KEY &
SERVER_PID=$!
echo ":; started grpc-go test server."
cleanup() {
echo ":; killing test server ${SERVER_PID}"
kill "${SERVER_PID}" || true
}
# trap exits to make sure we kill the server process when the script exits,
# regardless of why (errors, SIGTERM, etc).
trap cleanup EXIT
sleep 3
./target/debug/client --codec=prost --test_case="${JOINED_TEST_CASES}" "${ARG}"
# Test a grpc rust client against a Go server.
./target/debug/client --codec=protobuf --test_case="${JOINED_TEST_CASES}" ${ARG}
echo ":; killing test server"; kill "${SERVER_PID}";
echo "Waiting for test server to exit..."
while kill -0 ${SERVER_PID} 2> /dev/null; do
sleep 0.5
done
CODECS=("prost" "protobuf")
for CODEC in "${CODECS[@]}"; do
# run the test server
./target/debug/server "${ARG}" --codec "${CODEC}" &
SERVER_PID=$!
echo ":; started tonic test server with the ${CODEC} codec."
sleep 3
./target/debug/client --codec=prost --test_case="${JOINED_TEST_CASES}" "${ARG}"
# Run client test cases
if [ -n "${ARG:-}" ]; then
TLS_ARRAY=( \
-use_tls \
-use_test_ca \
-server_host_override=foo.test.google.fr \
-ca_file="${TLS_CA}" \
)
else
TLS_ARRAY=()
fi
for CASE in "${TEST_CASES[@]}"; do
flags=( "-test_case=${CASE}" )
# Avoid unbound variable errors on MacOS with bash version < 4.4.
# See: https://stackoverflow.com/a/61551944
flags+=( ${TLS_ARRAY[@]+"${TLS_ARRAY[@]}"} )
interop/bin/client_"${OS}"_amd64"${EXT}" "${flags[@]}"
done
echo ":; killing test server"; kill "${SERVER_PID}";
echo "Waiting for test server to exit..."
while kill -0 ${SERVER_PID} 2> /dev/null; do
sleep 0.5
done
done