Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Dec 10, 2024
1 parent 99ed2c3 commit 93edbc1
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,10 @@ func TestRaftClusterStartTSOJob(t *testing.T) {
leaderServer := tc.GetLeaderServer()
re.NotNil(leaderServer)
leaderServer.BootstrapCluster()
allocator := tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
re.True(allocator.IsInitialize())
testutil.Eventually(re, func() bool {
allocator := tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
return allocator.IsInitialize()
})
tc.Destroy()
cancel()
// case 2: return ahead of time but no error when start raft cluster
Expand All @@ -660,8 +662,10 @@ func TestRaftClusterStartTSOJob(t *testing.T) {
err = tc.RunInitialServers()
re.NoError(err)
tc.WaitLeader()
allocator = tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
re.False(allocator.IsInitialize())
testutil.Eventually(re, func() bool {
allocator := tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
return !allocator.IsInitialize()
})
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/raftClusterReturn"))
tc.Destroy()
cancel()
Expand All @@ -675,12 +679,45 @@ func TestRaftClusterStartTSOJob(t *testing.T) {
err = tc.RunInitialServers()
re.NoError(err)
tc.WaitLeader()
allocator = tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
re.NoError(err)
re.False(allocator.IsInitialize())
testutil.Eventually(re, func() bool {
allocator := tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
return !allocator.IsInitialize()
})
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/raftClusterReturn"))
tc.Destroy()
cancel()
// case 4: multiple bootstrap in 3 pd cluster
ctx, cancel = context.WithCancel(context.Background())
tc, err = tests.NewTestCluster(ctx, 3, func(conf *config.Config, _ string) {
conf.LeaderLease = 300
})
re.NoError(err)
re.NoError(tc.RunInitialServers())
re.NotEmpty(tc.WaitLeader())
leaderServer = tc.GetLeaderServer()
re.NotNil(leaderServer)
name = leaderServer.GetLeader().GetName()
wg := sync.WaitGroup{}
for range 3 {
wg.Add(1)
go func() {
leaderServer.BootstrapCluster()
wg.Done()
}()
}
wg.Wait()
testutil.Eventually(re, func() bool {
allocator := leaderServer.GetServer().GetGlobalTSOAllocator()
return allocator.IsInitialize()
})
re.NoError(tc.ResignLeader())
re.NotEmpty(tc.WaitLeader())
testutil.Eventually(re, func() bool {
allocator := tc.GetServer(name).GetServer().GetGlobalTSOAllocator()
return !allocator.IsInitialize()
})
tc.Destroy()
cancel()
}

func newMetaStore(storeID uint64, addr, version string, state metapb.StoreState, deployPath string) *metapb.Store {
Expand Down

0 comments on commit 93edbc1

Please sign in to comment.