Skip to content

Commit

Permalink
disable Linearizable and fix unstable test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Aug 7, 2024
1 parent ef571b7 commit bcf5669
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
8 changes: 5 additions & 3 deletions pkg/utils/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/pkg/utils/typeutil"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
etcdtypes "go.etcd.io/etcd/client/pkg/v3/types"
Expand Down Expand Up @@ -119,12 +120,13 @@ func ListEtcdMembers(ctx context.Context, client *clientv3.Client) (*clientv3.Me
time.Sleep(time.Duration(d) * time.Second)
})
newCtx, cancel := context.WithTimeout(ctx, DefaultRequestTimeout)
listResp, err := client.MemberList(newCtx)
c := clientv3.RetryClusterClient(client)
resp, err := c.MemberList(newCtx, &etcdserverpb.MemberListRequest{Linearizable: false})
cancel()
if err != nil {
return listResp, errs.ErrEtcdMemberList.Wrap(err).GenWithStackByCause()
return (*clientv3.MemberListResponse)(resp), errs.ErrEtcdMemberList.Wrap(err).GenWithStackByCause()
}
return listResp, nil
return (*clientv3.MemberListResponse)(resp), nil
}

// RemoveEtcdMember removes a member by the given id.
Expand Down
12 changes: 10 additions & 2 deletions pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ 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 Down Expand Up @@ -781,7 +780,16 @@ func (suite *loopWatcherTestSuite) startEtcd(re *require.Assertions) {
suite.etcd = etcd1
<-etcd1.Server.ReadyNotify()
suite.cleans = append(suite.cleans, func() {
suite.etcd.Close()
if suite.etcd.Server != nil {
select {
case _, ok := <-suite.etcd.Err():
if !ok {
return
}
default:
}
suite.etcd.Close()
}
})
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/etcdutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ func NewTestEtcdCluster(t *testing.T, count int) (servers []*embed.Etcd, etcdCli
clean = func() {
etcdClient.Close()
for _, server := range servers {
if server != nil {
notifier := server.Server.StopNotify()
if server.Server != nil {
select {
case <-notifier:
case _, ok := <-server.Err():
if !ok {
return
}
default:
server.Close()
}
server.Close()
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,14 @@ func (suite *multipleServerTestSuite) TestReElectLeader() {
newLeaderName := suite.cluster.WaitLeader()
re.NotEqual(originLeaderName, newLeaderName)

suite.pdLeader = suite.cluster.GetServer(newLeaderName)
suite.pdLeader.ResignLeader()
newLeaderName = suite.cluster.WaitLeader()
re.Equal(originLeaderName, newLeaderName)

suite.pdLeader = suite.cluster.GetServer(newLeaderName)
rc = suite.pdLeader.GetServer().GetRaftCluster()
re.NotNil(rc)
rc.IsPrepared()
}

Expand Down
10 changes: 8 additions & 2 deletions tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,15 @@ func (suite *CommonTestSuite) TestBootstrapDefaultKeyspaceGroup() {
re.NoError(s.Run())

// transfer leader to the new server
originLeaderName := suite.pdLeader.GetLeader().GetName()
suite.pdLeader.ResignLeader()
suite.pdLeader = suite.cluster.GetServer(suite.cluster.WaitLeader())
newLeaderName := suite.cluster.WaitLeader()
suite.pdLeader = suite.cluster.GetServer(newLeaderName)
re.NotEqual(originLeaderName, newLeaderName)
check()
originLeaderName = suite.pdLeader.GetLeader().GetName()
suite.pdLeader.ResignLeader()
suite.pdLeader = suite.cluster.GetServer(suite.cluster.WaitLeader())
newLeaderName = suite.cluster.WaitLeader()
suite.pdLeader = suite.cluster.GetServer(newLeaderName)
re.NotEqual(originLeaderName, newLeaderName)
}

0 comments on commit bcf5669

Please sign in to comment.