Skip to content

Commit

Permalink
Add a retry config for test clients; check for no available clients
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcneely committed Jan 16, 2025
1 parent 276d020 commit 26516c4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,24 +764,41 @@ func (c *LocalCluster) recreateContainers() error {
// Client returns a grpc client that can talk to any Alpha in the cluster
func (c *LocalCluster) Client() (*dgraphapi.GrpcClient, func(), error) {
// TODO(aman): can we cache the connections?
retryPolicy := `{
"methodConfig": [{
"retryPolicy": {
"MaxAttempts": 4,
"InitialBackoff": ".01s",
"MaxBackoff": ".01s",
"BackoffMultiplier": 1.0,
"RetryableStatusCodes": [ "UNAVAILABLE" ]
}
}]
}`
var apiClients []api.DgraphClient
var conns []*grpc.ClientConn
for _, aa := range c.alphas {
if !aa.isRunning {
// QUESTIONS(shivaji): Should this be 'continue' instead of a break from the loop
break
}
url, err := aa.alphaURL(c)
if err != nil {
return nil, nil, errors.Wrap(err, "error getting health URL")
}
conn, err := grpc.Dial(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial(url,

Check failure on line 789 in dgraphtest/local_cluster.go

View check run for this annotation

Trunk.io / Trunk Check

golangci-lint(staticcheck)

[new] SA1019: grpc.Dial is deprecated: use NewClient instead. Will be supported throughout 1.x.
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(retryPolicy))
if err != nil {
return nil, nil, errors.Wrap(err, "error connecting to alpha")
}
conns = append(conns, conn)
apiClients = append(apiClients, api.NewDgraphClient(conn))
}

if len(apiClients) == 0 {
return nil, nil, errors.New("no alphas running")
}
client := dgo.NewDgraphClient(apiClients...)
cleanup := func() {
for _, conn := range conns {
Expand Down

0 comments on commit 26516c4

Please sign in to comment.