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
17 changes: 15 additions & 2 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,27 @@ func (api *API) GetGates(ctx context.Context, req *vtadminpb.GetGatesRequest) (*
go func(c *cluster.Cluster) {
defer wg.Done()

g, err := c.Discovery.DiscoverVTGates(ctx, []string{})
gs, err := c.Discovery.DiscoverVTGates(ctx, []string{})
if err != nil {
er.RecordError(err)
return
}

m.Lock()
gates = append(gates, g...)

for _, g := range gs {
gates = append(gates, &vtadminpb.VTGate{
Cell: g.Cell,
Cluster: &vtadminpb.Cluster{
Id: c.ID,
Name: c.Name,
},
Hostname: g.Hostname,
Keyspaces: g.Keyspaces,
Pool: g.Pool,
})
}

m.Unlock()
}(c)
}
Expand Down
40 changes: 36 additions & 4 deletions go/vt/vtadmin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,32 @@ func TestGetGates(t *testing.T) {
Hostname: "cluster1-gate3",
},
}

fakedisco1.AddTaggedGates(nil, cluster1Gates...)

expectedCluster1Gates := []*vtadminpb.VTGate{

@doeg doeg Feb 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined these expectedCluster*Gates slices rather than adding the Cluster field to the existing cluster*Gates slice. Prior, when I added the Cluster to a cluster*Gates slice, fakedisco added them as-is, meaning the test passed without exercising the new codepath.

{
Cluster: &vtadminpb.Cluster{
Id: cluster1.ID,
Name: cluster1.Name,
},
Hostname: "cluster1-gate1",
},
{
Cluster: &vtadminpb.Cluster{
Id: cluster1.ID,
Name: cluster1.Name,
},
Hostname: "cluster1-gate2",
},
{
Cluster: &vtadminpb.Cluster{
Id: cluster1.ID,
Name: cluster1.Name,
},
Hostname: "cluster1-gate3",
},
}

fakedisco2 := fakediscovery.New()
cluster2 := &cluster.Cluster{
ID: "c2",
Expand All @@ -83,19 +106,28 @@ func TestGetGates(t *testing.T) {
Hostname: "cluster2-gate1",
},
}

fakedisco2.AddTaggedGates(nil, cluster2Gates...)

expectedCluster2Gates := []*vtadminpb.VTGate{
{
Cluster: &vtadminpb.Cluster{
Id: cluster2.ID,
Name: cluster2.Name,
},
Hostname: "cluster2-gate1",
},
}

api := NewAPI([]*cluster.Cluster{cluster1, cluster2}, grpcserver.Options{}, http.Options{})
ctx := context.Background()

resp, err := api.GetGates(ctx, &vtadminpb.GetGatesRequest{})
assert.NoError(t, err)
assert.ElementsMatch(t, append(cluster1Gates, cluster2Gates...), resp.Gates)
assert.ElementsMatch(t, append(expectedCluster1Gates, expectedCluster2Gates...), resp.Gates)

resp, err = api.GetGates(ctx, &vtadminpb.GetGatesRequest{ClusterIds: []string{cluster1.ID}})
assert.NoError(t, err)
assert.ElementsMatch(t, cluster1Gates, resp.Gates)
assert.ElementsMatch(t, expectedCluster1Gates, resp.Gates)

fakedisco1.SetGatesError(true)

Expand Down