Skip to content

Commit 61beb2b

Browse files
authored
Fix slow test startup (#5245)
* Invoke method in healthzServer when conn is Idle * Add Bazel diff
1 parent 250bec2 commit 61beb2b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

examples/internal/gateway/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ go_library(
1919
"@org_golang_google_grpc//connectivity",
2020
"@org_golang_google_grpc//credentials/insecure",
2121
"@org_golang_google_grpc//grpclog",
22+
"@org_golang_google_protobuf//types/known/emptypb",
2223
],
2324
)
2425

examples/internal/gateway/handlers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"google.golang.org/grpc"
1212
"google.golang.org/grpc/connectivity"
1313
"google.golang.org/grpc/grpclog"
14+
"google.golang.org/protobuf/types/known/emptypb"
1415
)
1516

1617
// openAPIServer returns OpenAPI specification files located under "/openapiv2/"
@@ -59,6 +60,10 @@ func preflightHandler(w http.ResponseWriter, r *http.Request) {
5960
func healthzServer(conn *grpc.ClientConn) http.HandlerFunc {
6061
return func(w http.ResponseWriter, r *http.Request) {
6162
w.Header().Set("Content-Type", "text/plain")
63+
if s := conn.GetState(); s == connectivity.Idle {
64+
// Invoke method to move connection from Idle to Ready
65+
conn.Invoke(r.Context(), "/grpc.health.v1.Health/Check", &emptypb.Empty{}, &emptypb.Empty{})
66+
}
6267
if s := conn.GetState(); s != connectivity.Ready {
6368
http.Error(w, fmt.Sprintf("grpc server is %s", s), http.StatusBadGateway)
6469
return

0 commit comments

Comments
 (0)