Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(release/v20.07) test: Fix flakiness in group_delete_test.go #6626

Merged
merged 1 commit into from
Oct 2, 2020
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
21 changes: 18 additions & 3 deletions systest/group-delete/group_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ import (
func NodesSetup(t *testing.T, c *dgo.Dgraph) {
ctx := context.Background()

require.NoError(t, c.Alter(ctx, &api.Operation{DropAll: true}))
// Retry DropAll to make sure the nodes is up and running.
var err error
for i := 0; i < 3; i ++ {
if err =c.Alter(ctx, &api.Operation{DropAll: true}); err != nil {
time.Sleep(5*time.Second)
continue
}
break
}
require.NoError(t, err, "error while dropping all the data")

schema, err := ioutil.ReadFile(`../data/goldendata.schema`)
require.NoError(t, err)
Expand Down Expand Up @@ -157,7 +166,10 @@ func TestNodes(t *testing.T) {
t.Errorf("moving tablets failed")
}

resp, err := http.Get("http://" + testutil.SockAddrZeroHttp + "/removeNode?group=3&id=3")
groupNodes, err := testutil.GetNodesInGroup("3")
require.NoError(t, err)
resp, err := http.Get("http://" + testutil.SockAddrZeroHttp + "/removeNode?group=3&id=" +
groupNodes[0])
require.NoError(t, err)
require.NoError(t, getError(resp.Body))

Expand Down Expand Up @@ -191,7 +203,10 @@ func TestNodes(t *testing.T) {
t.Errorf("moving tablets failed")
}

resp, err = http.Get("http://" + testutil.SockAddrZeroHttp + "/removeNode?group=2&id=2")
groupNodes, err = testutil.GetNodesInGroup("2")
require.NoError(t, err)
resp, err = http.Get("http://" + testutil.SockAddrZeroHttp + "/removeNode?group=2&id=" +
groupNodes[0])
require.NoError(t, err)
require.NoError(t, getError(resp.Body))

Expand Down
53 changes: 41 additions & 12 deletions testutil/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ import (
"google.golang.org/grpc"
)

type Member struct {
Addr string `json:"addr"`
GroupID int `json:"groupId"`
ID string `json:"id"`
LastUpdate string `json:"lastUpdate"`
Leader bool `json:"leader"`
}

// StateResponse represents the structure of the JSON object returned by calling
// the /state endpoint in zero.
type StateResponse struct {
Groups map[string]struct {
Members map[string]struct {
Addr string `json:"addr"`
GroupID int `json:"groupId"`
ID string `json:"id"`
LastUpdate string `json:"lastUpdate"`
Leader bool `json:"leader"`
} `json:"members"`
Members map[string]Member `json:"members"`
Tablets map[string]struct {
GroupID int `json:"groupId"`
Predicate string `json:"predicate"`
Expand Down Expand Up @@ -79,22 +81,27 @@ func GetState() (*StateResponse, error) {
}

// GetClientToGroup returns a dgraph client connected to an alpha in the given group.
func GetClientToGroup(groupID string) (*dgo.Dgraph, error) {
func GetClientToGroup(gid string) (*dgo.Dgraph, error) {
state, err := GetState()
if err != nil {
return nil, err
}

group, ok := state.Groups[groupID]
group, ok := state.Groups[gid]
if !ok {
return nil, errors.Errorf("group %s does not exist", groupID)
return nil, errors.Errorf("group %s does not exist", gid)
}

if len(group.Members) == 0 {
return nil, errors.Errorf("the group %s has no members", groupID)
return nil, errors.Errorf("the group %s has no members", gid)
}

member := group.Members["1"]
// Select the first member found in the iteration.
var member Member
for _, m := range group.Members {
member = m
break
}
parts := strings.Split(member.Addr, ":")
if len(parts) != 2 {
return nil, errors.Errorf("the member has an invalid address: %v", member.Addr)
Expand All @@ -114,3 +121,25 @@ func GetClientToGroup(groupID string) (*dgo.Dgraph, error) {
}
return dgo.NewDgraphClient(api.NewDgraphClient(conn)), nil
}

func GetNodesInGroup(gid string) ([]string, error) {
state, err := GetState()
if err != nil {
return nil, err
}

group, ok := state.Groups[gid]
if !ok {
return nil, errors.Errorf("group %s does not exist", gid)
}

if len(group.Members) == 0 {
return nil, errors.Errorf("the group %s has no members", gid)
}

nodes := make([]string, 0)
for id := range group.Members {
nodes = append(nodes, id)
}
return nodes, nil
}