diff --git a/.travis.yml b/.travis.yml index c6762c23..0afc362e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,3 +37,4 @@ script: - if [[ "${GAE}" = 1 ]]; then make testappengine; exit 0; fi - if [[ "${RACE}" = 1 ]]; then make testrace; exit 0; fi - make test + - examples/helloworld/helloworld_test.sh diff --git a/examples/helloworld/greeter_client/main.go b/examples/helloworld/greeter_client/main.go index f908170c..0ca4cbaa 100644 --- a/examples/helloworld/greeter_client/main.go +++ b/examples/helloworld/greeter_client/main.go @@ -36,7 +36,7 @@ const ( func main() { // Set up a connection to the server. - conn, err := grpc.Dial(address, grpc.WithInsecure()) + conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock()) if err != nil { log.Fatalf("did not connect: %v", err) } diff --git a/examples/helloworld/helloworld_test.sh b/examples/helloworld/helloworld_test.sh new file mode 100755 index 00000000..ea53cddb --- /dev/null +++ b/examples/helloworld/helloworld_test.sh @@ -0,0 +1,93 @@ +#!/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 + +clean () { + jobs -p | xargs -n 1 pkill -P + wait +} + +fail () { + echo "$(tput setaf 1) $1 $(tput sgr 0)" + clean + exit 1 +} + +pass () { + echo $"$(tput setaf 2) $1 $(tput sgr 0)" +} + +# Build greeter server +if ! go build -o /dev/null ./examples/helloworld/greeter_server/*.go; then + fail "failed to build greeter server" +else + pass "successfully built greeter server" +fi + +# Build greeter client +if ! go build -o /dev/null ./examples/helloworld/greeter_client/*.go; then + fail "failed to build greeter client" +else + pass "successfully built greeter client" +fi + +# Server should be able to start +SERVER_LOG="$(mktemp)" +go run examples/helloworld/greeter_server/*.go &> $SERVER_LOG & + +# Client should be able to communicate to the active server +CLIENT_LOG="$(mktemp)" +if ! go run examples/helloworld/greeter_client/*.go &> $CLIENT_LOG; then + fail "client failed to communicate with server + Got server log: + $(cat $SERVER_LOG) + Got client log: + $(cat $CLIENT_LOG) + " +else + pass "client successfully communicated with server" +fi + +# Out log should contain the string 'Received: world' +# from the server. +if ! grep -q "Received: world" $SERVER_LOG; then + fail "Server log missing server output: 'Received: world' + Got server log: + $(cat $SERVER_LOG) + Got client log: + $(cat $CLIENT_LOG) + " +else + pass "Server log contains server output: 'Received: world'" +fi + +# Out log should contain the string 'Greeting: Hello world' +# from the client. +if ! grep -q "Greeting: Hello world" $CLIENT_LOG ; then + fail "Client log missing client output: 'Greeting: Hello world' + Got server log: + $(cat $SERVER_LOG) + Got client log: + $(cat $CLIENT_LOG) + " +else + pass "Client log contains client output: 'Greeting: Hello world'" +fi + +clean +