diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-16 16:07:38 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-17 10:39:21 +0300 |
commit | 716607353210ca6f0148c528075636e3c529a788 (patch) | |
tree | 1ccdb77f916d73374692329cbe63438052860539 /tools | |
parent | e78d4dc2e9734dc01432e8999f15648c5579e2c8 (diff) |
tools/test-boot: Use gRPC client to connect to Gitaly
When Gitaly starts, we try to connect to its Unix socket via a call to
`net.Dial()`. Let's instead use a proper gRPC client, which also allows
us to make better use of gRPCs retry mechanisms instead of having to
manually sleep after every failed try.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/test-boot/main.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/test-boot/main.go b/tools/test-boot/main.go index 3f779cb7b..36623332b 100644 --- a/tools/test-boot/main.go +++ b/tools/test-boot/main.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "log" - "net" "os" "os/exec" "path/filepath" @@ -15,6 +14,8 @@ import ( "time" "github.com/urfave/cli/v2" + "gitlab.com/gitlab-org/gitaly/v16/client" + "google.golang.org/grpc" ) type gitalyConfig struct { @@ -111,15 +112,22 @@ func spawnAndWait(ctx context.Context, gitalyBin, configPath, socketPath string) start := time.Now() for i := 0; i < 100; i++ { - conn, err := net.Dial("unix", socketPath) - if err == nil { - fmt.Printf("\n\nconnection established after %v\n\n", time.Since(start)) - conn.Close() - return nil + ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) + + conn, err := client.DialContext(ctx, "unix://"+socketPath, []grpc.DialOption{ + grpc.WithBlock(), + }) + + cancel() + + if err != nil { + fmt.Printf(".") + continue } - fmt.Printf(".") - time.Sleep(100 * time.Millisecond) + fmt.Printf("\n\nconnection established after %v\n\n", time.Since(start)) + conn.Close() + return nil } fmt.Println("") |