github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/interop/interop_test.sh (about) 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 18 set -e +x 19 20 export TMPDIR=$(mktemp -d) 21 trap "rm -rf ${TMPDIR}" EXIT 22 23 clean () { 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 38 fail () { 39 echo "$(tput setaf 1) $1 $(tput sgr 0)" 40 clean 41 exit 1 42 } 43 44 pass () { 45 echo "$(tput setaf 2) $1 $(tput sgr 0)" 46 } 47 48 # Don't run some tests that need a special environment: 49 # "google_default_credentials" 50 # "compute_engine_channel_credentials" 51 # "compute_engine_creds" 52 # "service_account_creds" 53 # "jwt_token_creds" 54 # "oauth2_auth_token" 55 # "per_rpc_creds" 56 # "pick_first_unary" 57 58 CASES=( 59 "empty_unary" 60 "large_unary" 61 "client_streaming" 62 "server_streaming" 63 "ping_pong" 64 "empty_stream" 65 "timeout_on_sleeping_server" 66 "cancel_after_begin" 67 "cancel_after_first_response" 68 "status_code_and_message" 69 "special_status_message" 70 "custom_metadata" 71 "unimplemented_method" 72 "unimplemented_service" 73 ) 74 75 # Build server 76 if ! go build -o /dev/null ./interop/server; then 77 fail "failed to build server" 78 else 79 pass "successfully built server" 80 fi 81 82 # Start server 83 SERVER_LOG="$(mktemp)" 84 go run ./interop/server --use_tls &> $SERVER_LOG & 85 86 for case in ${CASES[@]}; do 87 echo "$(tput setaf 4) testing: ${case} $(tput sgr 0)" 88 89 CLIENT_LOG="$(mktemp)" 90 if ! timeout 20 go run ./interop/client --use_tls --server_host_override=foo.test.google.fr --use_test_ca --test_case="${case}" &> $CLIENT_LOG; then 91 fail "FAIL: test case ${case} 92 got server log: 93 $(cat $SERVER_LOG) 94 got client log: 95 $(cat $CLIENT_LOG) 96 " 97 else 98 pass "PASS: test case ${case}" 99 fi 100 done 101 102 clean