From 895b36ddf2f9cad65b1ee8514e430c9fa493eda8 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Wed, 4 Dec 2019 15:55:45 -0800 Subject: [PATCH] travis: run interop tests with examples (#3229) --- .travis.yml | 4 +- interop/interop_test.sh | 102 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100755 interop/interop_test.sh diff --git a/.travis.yml b/.travis.yml index 87f40b83..819c1e2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ matrix: - go: 1.13.x env: GRPC_GO_RETRY=on - go: 1.13.x - env: TESTEXAMPLES=1 + env: TESTEXTRAS=1 - go: 1.12.x env: GO111MODULE=on - go: 1.11.x @@ -35,7 +35,7 @@ install: script: - set -e - - if [[ -n "${TESTEXAMPLES}" ]]; then examples/examples_test.sh; exit 0; fi + - if [[ -n "${TESTEXTRAS}" ]]; then examples/examples_test.sh; interop/interop_test.sh; exit 0; fi - if [[ -n "${VET}" ]]; then ./vet.sh; fi - if [[ -n "${GAE}" ]]; then make testappengine; exit 0; fi - if [[ -n "${RACE}" ]]; then make testrace; exit 0; fi diff --git a/interop/interop_test.sh b/interop/interop_test.sh new file mode 100755 index 00000000..15bf9cc0 --- /dev/null +++ b/interop/interop_test.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# +# Copyright 2019 gRPC authors. +# +# 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 +# +# http://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. +# + +set -e +x + +export TMPDIR=$(mktemp -d) +trap "rm -rf ${TMPDIR}" EXIT + +clean () { + for i in {1..10}; do + jobs -p | xargs -n1 pkill -P + # A simple "wait" just hangs sometimes. Running `jobs` seems to help. + sleep 1 + if jobs | read; then + return + fi + done + echo "$(tput setaf 1) clean failed to kill tests $(tput sgr 0)" + jobs + pstree + exit 1 +} + +fail () { + echo "$(tput setaf 1) $1 $(tput sgr 0)" + clean + exit 1 +} + +pass () { + echo "$(tput setaf 2) $1 $(tput sgr 0)" +} + +# Don't run some tests that need a special environment: +# "google_default_credentials" +# "compute_engine_channel_credentials" +# "compute_engine_creds" +# "service_account_creds" +# "jwt_token_creds" +# "oauth2_auth_token" +# "per_rpc_creds" +# "pick_first_unary" + +CASES=( + "empty_unary" + "large_unary" + "client_streaming" + "server_streaming" + "ping_pong" + "empty_stream" + "timeout_on_sleeping_server" + "cancel_after_begin" + "cancel_after_first_response" + "status_code_and_message" + "special_status_message" + "custom_metadata" + "unimplemented_method" + "unimplemented_service" +) + +# Build server +if ! go build -o /dev/null ./interop/server; then + fail "failed to build server" +else + pass "successfully built server" +fi + +# Start server +SERVER_LOG="$(mktemp)" +go run ./interop/server --use_tls &> $SERVER_LOG & + +for case in ${CASES[@]}; do + echo "$(tput setaf 4) testing: ${case} $(tput sgr 0)" + + CLIENT_LOG="$(mktemp)" + 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 + fail "FAIL: test case ${case} + got server log: + $(cat $SERVER_LOG) + got client log: + $(cat $CLIENT_LOG) + " + else + pass "PASS: test case ${case}" + fi +done + +clean