examples: add regression test script to hello world example (#3092)
This commit is contained in:
Родитель
7c3115d8bb
Коммит
b53233ce4c
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
Загрузка…
Ссылка в новой задаче