Skip to content

Commit

Permalink
*: make TestEtcdClientSync stable (#8084)
Browse files Browse the repository at this point in the history
close #8085

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] committed Apr 17, 2024
1 parent db88a43 commit afdd48f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestEtcdClientSync(t *testing.T) {
servers, client1, clean := NewTestEtcdCluster(t, 1)
defer clean()
etcd1, cfg1 := servers[0], servers[0].Config()
defer etcd1.Close()

// Add a new member.
etcd2 := MustAddEtcdMember(t, &cfg1, client1)
Expand All @@ -180,10 +181,22 @@ func TestEtcdClientSync(t *testing.T) {
// wait for etcd client sync endpoints
checkEtcdEndpointNum(re, client1, 2)

// Remove the first member and close the etcd1.
_, err := RemoveEtcdMember(client1, uint64(etcd1.Server.ID()))
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
// remove one member that is not the one we connected to.
resp, err := ListEtcdMembers(ctx, client1)
re.NoError(err)

var memIDToRemove uint64
for _, m := range resp.Members {
if m.ID != resp.Header.MemberId {
memIDToRemove = m.ID
break
}
}

_, err = RemoveEtcdMember(client1, memIDToRemove)
re.NoError(err)
etcd1.Close()

// Check the client can get the new member with the new endpoints.
checkEtcdEndpointNum(re, client1, 1)
Expand Down

0 comments on commit afdd48f

Please sign in to comment.