examples: add examples regression test script (#3118)
This commit is contained in:
Родитель
8eafb5b7d5
Коммит
8988da6e70
|
@ -37,4 +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
|
||||
- examples/examples_test.sh
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
#!/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
|
||||
|
||||
export TMPDIR=$(mktemp -d)
|
||||
trap "rm -rf ${TMPDIR}" EXIT
|
||||
|
||||
clean () {
|
||||
jobs -p | xargs pkill -P
|
||||
wait
|
||||
}
|
||||
|
||||
fail () {
|
||||
echo "$(tput setaf 1) $1 $(tput sgr 0)"
|
||||
clean
|
||||
exit 1
|
||||
}
|
||||
|
||||
pass () {
|
||||
echo "$(tput setaf 2) $1 $(tput sgr 0)"
|
||||
}
|
||||
|
||||
EXAMPLES=(
|
||||
"helloworld"
|
||||
"route_guide"
|
||||
"features/authentication"
|
||||
"features/compression"
|
||||
"features/deadline"
|
||||
"features/encryption/TLS"
|
||||
"features/errors"
|
||||
"features/interceptor"
|
||||
"features/load_balancing"
|
||||
"features/metadata"
|
||||
"features/multiplex"
|
||||
"features/name_resolving"
|
||||
)
|
||||
|
||||
declare -A EXPECTED_SERVER_OUTPUT=(
|
||||
["helloworld"]="Received: world"
|
||||
["route_guide"]=""
|
||||
["features/authentication"]="server starting on port 50051..."
|
||||
["features/compression"]="UnaryEcho called with message \"compress\""
|
||||
["features/deadline"]=""
|
||||
["features/encryption/TLS"]=""
|
||||
["features/errors"]=""
|
||||
["features/interceptor"]="unary echoing message \"hello world\""
|
||||
["features/load_balancing"]="serving on :50051"
|
||||
["features/metadata"]="message:\"this is examples/metadata\" , sending echo"
|
||||
["features/multiplex"]=":50051"
|
||||
["features/name_resolving"]="serving on localhost:50051"
|
||||
)
|
||||
|
||||
declare -A EXPECTED_CLIENT_OUTPUT=(
|
||||
["helloworld"]="Greeting: Hello world"
|
||||
["route_guide"]="location:<latitude:416851321 longitude:-742674555 >"
|
||||
["features/authentication"]="UnaryEcho: hello world"
|
||||
["features/compression"]="UnaryEcho call returned \"compress\", <nil>"
|
||||
["features/deadline"]="wanted = DeadlineExceeded, got = DeadlineExceeded"
|
||||
["features/encryption/TLS"]="UnaryEcho: hello world"
|
||||
["features/errors"]="Greeting: Hello world"
|
||||
["features/interceptor"]="UnaryEcho: hello world"
|
||||
["features/load_balancing"]="calling helloworld.Greeter/SayHello with pick_first"
|
||||
["features/metadata"]="this is examples/metadata"
|
||||
["features/multiplex"]="Greeting: Hello multiplex"
|
||||
["features/name_resolving"]="calling helloworld.Greeter/SayHello to \"example:///resolver.example.grpc.io\""
|
||||
)
|
||||
|
||||
for example in ${EXAMPLES[@]}; do
|
||||
echo "$(tput setaf 4) testing: ${example} $(tput sgr 0)"
|
||||
|
||||
# Build server
|
||||
if ! go build -o /dev/null ./examples/${example}/*server/*.go; then
|
||||
fail "failed to build server"
|
||||
else
|
||||
pass "successfully built server"
|
||||
fi
|
||||
|
||||
# Build client
|
||||
if ! go build -o /dev/null ./examples/${example}/*client/*.go; then
|
||||
fail "failed to build client"
|
||||
else
|
||||
pass "successfully built client"
|
||||
fi
|
||||
|
||||
# Start server
|
||||
SERVER_LOG="$(mktemp)"
|
||||
go run ./examples/$example/*server/*.go &> $SERVER_LOG &
|
||||
|
||||
CLIENT_LOG="$(mktemp)"
|
||||
if ! timeout 20 go run examples/${example}/*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 communitcated with server"
|
||||
fi
|
||||
|
||||
# Check server log for expected output if expecting an
|
||||
# output
|
||||
if [ -n "${EXPECTED_SERVER_OUTPUT[$example]}" ]; then
|
||||
if ! grep -q "${EXPECTED_SERVER_OUTPUT[$example]}" $SERVER_LOG; then
|
||||
fail "server log missing output: ${EXPECTED_SERVER_OUTPUT[$example]}
|
||||
got server log:
|
||||
$(cat $SERVER_LOG)
|
||||
got client log:
|
||||
$(cat $CLIENT_LOG)
|
||||
"
|
||||
else
|
||||
pass "server log contains expected output: ${EXPECTED_SERVER_OUTPUT[$example]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check client log for expected output if expecting an
|
||||
# output
|
||||
if [ -n "${EXPECTED_CLIENT_OUTPUT[$example]}" ]; then
|
||||
if ! grep -q "${EXPECTED_CLIENT_OUTPUT[$example]}" $CLIENT_LOG; then
|
||||
fail "client log missing output: ${EXPECTED_CLIENT_OUTPUT[$example]}
|
||||
got server log:
|
||||
$(cat $SERVER_LOG)
|
||||
got client log:
|
||||
$(cat $CLIENT_LOG)
|
||||
"
|
||||
else
|
||||
pass "client log contains expected output: ${EXPECTED_CLIENT_OUTPUT[$example]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
clean
|
||||
done
|
||||
|
|
@ -66,6 +66,7 @@ func main() {
|
|||
grpc.WithTransportCredentials(creds),
|
||||
}
|
||||
|
||||
opts = append(opts, grpc.WithBlock())
|
||||
conn, err := grpc.Dial(*addr, opts...)
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
|
|
|
@ -37,7 +37,7 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func streamingCall(c pb.EchoClient, requestID int, message string, want codes.Co
|
|||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func main() {
|
|||
altsTC := alts.NewClientCreds(alts.DefaultClientOptions())
|
||||
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(altsTC))
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds))
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithStreamInterceptor(streamInterceptor))
|
||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithStreamInterceptor(streamInterceptor), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ func main() {
|
|||
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
|
||||
// grpc.WithBalancerName("pick_first"), // "pick_first" is the default, so this DialOption is not necessary.
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithBlock(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
|
@ -75,6 +76,7 @@ func main() {
|
|||
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
|
||||
grpc.WithBalancerName("round_robin"), // This sets the initial balancing policy.
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithBlock(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
|
|
|
@ -286,7 +286,7 @@ const message = "this is examples/metadata"
|
|||
func main() {
|
||||
flag.Parse()
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func callUnaryEcho(client ecpb.EchoClient, message string) {
|
|||
func main() {
|
||||
flag.Parse()
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithBlock())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ func main() {
|
|||
passthroughConn, err := grpc.Dial(
|
||||
fmt.Sprintf("passthrough:///%s", backendAddr), // Dial to "passthrough:///localhost:50051"
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithBlock(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
|
@ -72,6 +73,7 @@ func main() {
|
|||
exampleConn, err := grpc.Dial(
|
||||
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName), // Dial to "example:///resolver.example.grpc.io"
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithBlock(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
#!/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
|
||||
|
|
@ -165,6 +165,8 @@ func main() {
|
|||
} else {
|
||||
opts = append(opts, grpc.WithInsecure())
|
||||
}
|
||||
|
||||
opts = append(opts, grpc.WithBlock())
|
||||
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||
if err != nil {
|
||||
log.Fatalf("fail to dial: %v", err)
|
||||
|
|
Загрузка…
Ссылка в новой задаче