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

test/cluster_test: make TestRegionStatistics more stable #8320

Merged
merged 3 commits into from
Jun 25, 2024
Merged
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: 10 additions & 11 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestRegionStatistics(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tc, err := tests.NewTestCluster(ctx, 2)
tc, err := tests.NewTestCluster(ctx, 3)
Copy link
Member

Choose a reason for hiding this comment

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

Why add a new server?

Copy link
Member Author

@HuSharp HuSharp Jun 24, 2024

Choose a reason for hiding this comment

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

Because this test has only 2 pd's and five ResignLeader times, whenever there is a network or disk problem(ci machine has a high probability) will cause the lease to expire, and result in one more leader resigning.
And then there is a high probability of being recognized as frequent campaign times to transfer leader failed

defer tc.Destroy()
re.NoError(err)

Expand Down Expand Up @@ -223,9 +223,9 @@ func TestRegionStatistics(t *testing.T) {
time.Sleep(1000 * time.Millisecond)

leaderServer.ResignLeader()
newLeaderName := tc.WaitLeader()
re.NotEqual(newLeaderName, leaderName)
re.NotEqual(tc.WaitLeader(), leaderName)
leaderServer = tc.GetLeaderServer()
leaderName = leaderServer.GetServer().Name()
rc = leaderServer.GetRaftCluster()
r := rc.GetRegion(region.Id)
re.NotNil(r)
Expand All @@ -238,9 +238,9 @@ func TestRegionStatistics(t *testing.T) {
re.Len(regions, 1)

leaderServer.ResignLeader()
newLeaderName = tc.WaitLeader()
re.Equal(newLeaderName, leaderName)
re.NotEqual(tc.WaitLeader(), leaderName)
leaderServer = tc.GetLeaderServer()
leaderName = leaderServer.GetServer().Name()
rc = leaderServer.GetRaftCluster()
re.NotNil(r)
re.True(r.LoadedFromStorage() || r.LoadedFromSync())
Expand All @@ -255,13 +255,12 @@ func TestRegionStatistics(t *testing.T) {
re.False(r.LoadedFromStorage() && r.LoadedFromSync())

leaderServer.ResignLeader()
newLeaderName = tc.WaitLeader()
re.NotEqual(newLeaderName, leaderName)
leaderServer.ResignLeader()
newLeaderName = tc.WaitLeader()
re.Equal(newLeaderName, leaderName)
re.NotEqual(tc.WaitLeader(), leaderName)
leaderServer = tc.GetLeaderServer()
rc = leaderServer.GetRaftCluster()
leaderName = leaderServer.GetServer().Name()
leaderServer.ResignLeader()
re.NotEqual(tc.WaitLeader(), leaderName)
rc = tc.GetLeaderServer().GetRaftCluster()
r = rc.GetRegion(region.Id)
re.NotNil(r)
re.False(r.LoadedFromStorage() && r.LoadedFromSync())
Expand Down
Loading