diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-08 13:32:28 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-08 17:10:02 +0300 |
commit | fc0e04c1f01d19056b07948c8b845f992fa65922 (patch) | |
tree | 00112f527e26971f6e5224bfe139f97d249492b7 | |
parent | 5e98fa816196058e003b45fd18477525a78b8823 (diff) |
testserver: Drop retry when waiting for server to become healthy
When executing `waitHealthy()`, then we retry connecting to the health
client, where each retry is limited to 1 second. This shouldn't be
necessary though:
- `grpc.WaitForReady()` ensures that we retry connecting to the
service until we're either successful or until the context times
out. It's thus useless to re-dial.
- When instantiating the health server, it will always be
initialized in "serving" state for the default service.
Furthermore, we only ever check for the default service and never
modify the serving status of the server. As such, if we ever
receive an answer from the server, then it must be that it is
serving. It's thus useless to retry the RPC call.
In combination, it means that we do not need to loop at all in
`waitHealthy()`.
Simplify the function to not loop, but instead use a 3 second timeout
both for dialing the server and executing the health check.
-rw-r--r-- | internal/testhelper/testserver/gitaly.go | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go index 36fa324f0..197a2a1aa 100644 --- a/internal/testhelper/testserver/gitaly.go +++ b/internal/testhelper/testserver/gitaly.go @@ -191,38 +191,21 @@ func waitHealthy(t testing.TB, cfg config.Cfg, addr string) { grpcOpts = append(grpcOpts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(cfg.Auth.Token))) } - conn, err := grpc.Dial(addr, grpcOpts...) - require.NoError(t, err) - defer conn.Close() - - for i := 0; i < 3; i++ { - if IsHealthy(conn, time.Second) { - return - } - } + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() - require.FailNow(t, "server not yet ready to serve") -} + conn, err := grpc.DialContext(ctx, addr, grpcOpts...) + require.NoError(t, err) + defer testhelper.MustClose(t, conn) -// IsHealthy creates a health client to passed in connection and send `Check` request. -// It waits for `timeout` duration to get response back. -// It returns `true` only if remote responds with `SERVING` status. -func IsHealthy(conn *grpc.ClientConn, timeout time.Duration) bool { healthClient := healthpb.NewHealthClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - resp, err := healthClient.Check(ctx, &healthpb.HealthCheckRequest{}, grpc.WaitForReady(true)) - if err != nil { - return false - } + require.NoError(t, err) if resp.Status != healthpb.HealthCheckResponse_SERVING { - return false + require.FailNow(t, "server not yet ready to serve") } - - return true } func runGitaly(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server, registrar func(srv *grpc.Server, deps *service.Dependencies), opts ...GitalyServerOpt) (*grpc.Server, string, bool) { |