Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/examples_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,18 @@ for example in ${EXAMPLES[@]}; do
# 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
found=false

# Poll for up to 10 seconds.
for i in {1..10}; do
if grep -q "${EXPECTED_SERVER_OUTPUT[$example]}" "$SERVER_LOG"; then
found=true
break
fi
sleep 1
done

if [ "$found" = "false" ]; then
fail "server log missing output: ${EXPECTED_SERVER_OUTPUT[$example]}
got server log:
$(cat $SERVER_LOG)
Expand Down
12 changes: 12 additions & 0 deletions examples/features/gracefulstop/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func main() {
s := grpc.NewServer()
ss := &server{streamStart: make(chan struct{})}
pb.RegisterEchoServer(s, ss)
serverStopped := make(chan struct{}, 1)

go func() {
<-ss.streamStart // wait until server streaming starts
Expand All @@ -93,13 +94,24 @@ func main() {
timer := time.AfterFunc(10*time.Second, func() {
log.Println("Server couldn't stop gracefully in time. Doing force stop.")
s.Stop()
// Unblock the main function.
select {
case serverStopped <- struct{}{}:
default:
}
})
defer timer.Stop()
s.GracefulStop() // gracefully stop server after in-flight server streaming rpc finishes
log.Println("Server stopped gracefully.")
// Unblock the main function.
select {
case serverStopped <- struct{}{}:
default:
}
}()

if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
<-serverStopped
}
Loading