...
1#!/bin/bash
2#
3# Copyright 2019 gRPC authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18set -e +x
19
20export TMPDIR=$(mktemp -d)
21trap "rm -rf ${TMPDIR}" EXIT
22
23clean () {
24 for i in {1..10}; do
25 jobs -p | xargs -n1 pkill -P
26 # A simple "wait" just hangs sometimes. Running `jobs` seems to help.
27 sleep 1
28 if jobs | read; then
29 return
30 fi
31 done
32 echo "$(tput setaf 1) clean failed to kill tests $(tput sgr 0)"
33 jobs
34 pstree
35 exit 1
36}
37
38fail () {
39 echo "$(tput setaf 1) $(date): $1 $(tput sgr 0)"
40 clean
41 exit 1
42}
43
44pass () {
45 echo "$(tput setaf 2) $(date): $1 $(tput sgr 0)"
46}
47
48withTimeout () {
49 timer=$1
50 shift
51
52 # Run command in the background.
53 cmd=$(printf '%q ' "$@")
54 eval "$cmd" &
55 wpid=$!
56 # Kill after $timer seconds.
57 sleep $timer && kill $wpid &
58 kpid=$!
59 # Wait for the background thread.
60 wait $wpid
61 res=$?
62 # Kill the killer pid in case it's still running.
63 kill $kpid || true
64 wait $kpid || true
65 return $res
66}
67
68# Don't run some tests that need a special environment:
69# "google_default_credentials"
70# "compute_engine_channel_credentials"
71# "compute_engine_creds"
72# "service_account_creds"
73# "jwt_token_creds"
74# "oauth2_auth_token"
75# "per_rpc_creds"
76# "pick_first_unary"
77
78CASES=(
79 "empty_unary"
80 "large_unary"
81 "client_streaming"
82 "server_streaming"
83 "ping_pong"
84 "empty_stream"
85 "timeout_on_sleeping_server"
86 "cancel_after_begin"
87 "cancel_after_first_response"
88 "status_code_and_message"
89 "special_status_message"
90 "custom_metadata"
91 "unimplemented_method"
92 "unimplemented_service"
93 "orca_per_rpc"
94 "orca_oob"
95)
96
97# Build server
98echo "$(tput setaf 4) $(date): building server $(tput sgr 0)"
99if ! go build -o /dev/null ./interop/server; then
100 fail "failed to build server"
101else
102 pass "successfully built server"
103fi
104
105# Build client
106echo "$(tput setaf 4) $(date): building client $(tput sgr 0)"
107if ! go build -o /dev/null ./interop/client; then
108 fail "failed to build client"
109else
110 pass "successfully built client"
111fi
112
113# Start server
114SERVER_LOG="$(mktemp)"
115GRPC_GO_LOG_SEVERITY_LEVEL=info go run ./interop/server --use_tls &> $SERVER_LOG &
116
117for case in ${CASES[@]}; do
118 echo "$(tput setaf 4) $(date): testing: ${case} $(tput sgr 0)"
119
120 CLIENT_LOG="$(mktemp)"
121 if ! GRPC_GO_LOG_SEVERITY_LEVEL=info withTimeout 20 go run ./interop/client \
122 --use_tls \
123 --server_host_override=foo.test.google.fr \
124 --use_test_ca --test_case="${case}" \
125 --service_config_json='{ "loadBalancingConfig": [{ "test_backend_metrics_load_balancer": {} }]}' \
126 &> $CLIENT_LOG; then
127 fail "FAIL: test case ${case}
128 got server log:
129 $(cat $SERVER_LOG)
130 got client log:
131 $(cat $CLIENT_LOG)
132 "
133 else
134 pass "PASS: test case ${case}"
135 fi
136done
137
138clean
View as plain text