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

*: clean up the testing environment #9000

Merged
merged 2 commits into from
Jan 16, 2025
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
4 changes: 1 addition & 3 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ func TestGetTSAfterTransferLeader(t *testing.T) {
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 2)
re.NoError(err)
defer cluster.Destroy()
endpoints := runServer(re, cluster)
leader := cluster.WaitLeader()
re.NotEmpty(leader)
defer cluster.Destroy()

cli := setupCli(ctx, re, endpoints, opt.WithCustomTimeoutOption(10*time.Second))
defer cli.Close()
Expand Down Expand Up @@ -517,8 +517,6 @@ func (suite *followerForwardAndHandleTestSuite) SetupSuite() {
})
}

func (*followerForwardAndHandleTestSuite) TearDownTest() {}

func (suite *followerForwardAndHandleTestSuite) TearDownSuite() {
suite.cluster.Destroy()
suite.clean()
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/mcs/tso/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ func TestTSOServerStartFirst(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

apiCluster, err := tests.NewTestClusterWithKeyspaceGroup(ctx, 1, func(conf *config.Config, _ string) {
cluster, err := tests.NewTestClusterWithKeyspaceGroup(ctx, 1, func(conf *config.Config, _ string) {
conf.Keyspace.PreAlloc = []string{"k1", "k2"}
})
defer apiCluster.Destroy()
defer cluster.Destroy()
re.NoError(err)
addr := apiCluster.GetConfig().GetClientURL()
addr := cluster.GetConfig().GetClientURL()
ch := make(chan struct{})
defer close(ch)
clusterCh := make(chan *tests.TestTSOCluster)
Expand All @@ -155,11 +155,11 @@ func TestTSOServerStartFirst(t *testing.T) {
clusterCh <- tsoCluster
ch <- struct{}{}
}()
err = apiCluster.RunInitialServers()
err = cluster.RunInitialServers()
re.NoError(err)
leaderName := apiCluster.WaitLeader()
leaderName := cluster.WaitLeader()
re.NotEmpty(leaderName)
pdLeaderServer := apiCluster.GetServer(leaderName)
pdLeaderServer := cluster.GetServer(leaderName)
re.NoError(pdLeaderServer.BootstrapCluster())
re.NoError(err)
tsoCluster := <-clusterCh
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/mcs/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) {
}
})
re.NoError(err)
defer tc.Destroy()
pdAddr := tc.GetConfig().GetClientURL()

// Start PD and tso server.
err = tc.RunInitialServers()
re.NoError(err)
defer tc.Destroy()
tc.WaitLeader()
leaderServer := tc.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
Expand Down Expand Up @@ -741,12 +741,12 @@ func TestGetTSOImmediately(t *testing.T) {
}
})
re.NoError(err)
defer tc.Destroy()
pdAddr := tc.GetConfig().GetClientURL()

// Start PD and tso server.
err = tc.RunInitialServers()
re.NoError(err)
defer tc.Destroy()
tc.WaitLeader()
leaderServer := tc.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
Expand Down
22 changes: 11 additions & 11 deletions tests/integrations/mcs/tso/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type tsoProxyTestSuite struct {
suite.Suite
ctx context.Context
cancel context.CancelFunc
apiCluster *tests.TestCluster
apiLeader *tests.TestServer
cluster *tests.TestCluster
leader *tests.TestServer
backendEndpoints string
tsoCluster *tests.TestTSOCluster
defaultReq *pdpb.TsoRequest
Expand All @@ -62,23 +62,23 @@ func (s *tsoProxyTestSuite) SetupSuite() {
var err error
s.ctx, s.cancel = context.WithCancel(context.Background())
// Create an API cluster with 1 server
s.apiCluster, err = tests.NewTestClusterWithKeyspaceGroup(s.ctx, 1)
s.cluster, err = tests.NewTestClusterWithKeyspaceGroup(s.ctx, 1)
re.NoError(err)
err = s.apiCluster.RunInitialServers()
err = s.cluster.RunInitialServers()
re.NoError(err)
leaderName := s.apiCluster.WaitLeader()
leaderName := s.cluster.WaitLeader()
re.NotEmpty(leaderName)
s.apiLeader = s.apiCluster.GetServer(leaderName)
s.backendEndpoints = s.apiLeader.GetAddr()
re.NoError(s.apiLeader.BootstrapCluster())
s.leader = s.cluster.GetServer(leaderName)
s.backendEndpoints = s.leader.GetAddr()
re.NoError(s.leader.BootstrapCluster())

// Create a TSO cluster with 2 servers
s.tsoCluster, err = tests.NewTestTSOCluster(s.ctx, 2, s.backendEndpoints)
re.NoError(err)
s.tsoCluster.WaitForDefaultPrimaryServing(re)

s.defaultReq = &pdpb.TsoRequest{
Header: &pdpb.RequestHeader{ClusterId: s.apiLeader.GetClusterID()},
Header: &pdpb.RequestHeader{ClusterId: s.leader.GetClusterID()},
Count: 1,
}

Expand All @@ -89,7 +89,7 @@ func (s *tsoProxyTestSuite) SetupSuite() {
func (s *tsoProxyTestSuite) TearDownSuite() {
cleanupGRPCStreams(s.cleanupFuncs)
s.tsoCluster.Destroy()
s.apiCluster.Destroy()
s.cluster.Destroy()
s.cancel()
}

Expand Down Expand Up @@ -362,7 +362,7 @@ func (s *tsoProxyTestSuite) generateRequests(requestsPerClient int) []*pdpb.TsoR
reqs := make([]*pdpb.TsoRequest, requestsPerClient)
for i := range requestsPerClient {
reqs[i] = &pdpb.TsoRequest{
Header: &pdpb.RequestHeader{ClusterId: s.apiLeader.GetClusterID()},
Header: &pdpb.RequestHeader{ClusterId: s.leader.GetClusterID()},
Count: uint32(i) + 1, // Make sure the count is positive.
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ func TestMixedTSODeployment(t *testing.T) {
}()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cancel()
defer cluster.Destroy()

err = cluster.RunInitialServers()
Expand Down Expand Up @@ -542,10 +542,12 @@ func TestMixedTSODeployment(t *testing.T) {
func TestUpgradingPDAndTSOClusters(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create an PD cluster which has 3 servers
pdCluster, err := tests.NewTestClusterWithKeyspaceGroup(ctx, 3)
re.NoError(err)
defer pdCluster.Destroy()
err = pdCluster.RunInitialServers()
re.NoError(err)
leaderName := pdCluster.WaitLeader()
Expand All @@ -569,20 +571,18 @@ func TestUpgradingPDAndTSOClusters(t *testing.T) {
mcs.WaitForTSOServiceAvailable(ctx, re, pdClient)

// Restart the API cluster
pdCluster, err = tests.RestartTestPDCluster(ctx, pdCluster)
_, err = tests.RestartTestPDCluster(ctx, pdCluster)
re.NoError(err)
// The TSO service should be eventually healthy
mcs.WaitForTSOServiceAvailable(ctx, re, pdClient)

// Restart the TSO cluster
tsoCluster, err = tests.RestartTestTSOCluster(ctx, tsoCluster)
re.NoError(err)
defer tsoCluster.Destroy()
// The TSO service should be eventually healthy
mcs.WaitForTSOServiceAvailable(ctx, re, pdClient)

tsoCluster.Destroy()
pdCluster.Destroy()
cancel()
re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/usePDServiceMode"))
}

Expand Down
2 changes: 2 additions & 0 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,11 @@ func TestRaftClusterStartTSOJob(t *testing.T) {
name := "pd1"
// case 1: normal start
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tc, err := tests.NewTestCluster(ctx, 1, func(conf *config.Config, _ string) {
conf.LeaderLease = 300
})
defer tc.Destroy()
re.NoError(err)
re.NoError(tc.RunInitialServers())
re.NotEmpty(tc.WaitLeader())
Expand Down
6 changes: 2 additions & 4 deletions tests/server/region_syncer/region_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ func TestMain(m *testing.M) {
func TestRegionSyncer(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/storage/levelDBStorageFastFlush", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/syncer/noFastExitSync", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/syncer/disableClientStreaming", `return(true)`))

cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config, _ string) { conf.PDServerCfg.UseRegionStorage = true })
defer func() {
cluster.Destroy()
cancel()
}()
defer cluster.Destroy()
re.NoError(err)

re.NoError(cluster.RunInitialServers())
Expand Down
8 changes: 5 additions & 3 deletions tests/server/storage/hot_region_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestHotRegionStorage(t *testing.T) {
},
)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
re.NotEmpty(cluster.WaitLeader())
Expand All @@ -67,7 +68,7 @@ func TestHotRegionStorage(t *testing.T) {
for _, store := range stores {
tests.MustPutStore(re, cluster, store)
}
defer cluster.Destroy()

startTime := time.Now().Unix()
tests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetWrittenBytes(3000000000),
core.SetReportInterval(uint64(startTime-utils.RegionHeartBeatReportInterval), uint64(startTime)))
Expand Down Expand Up @@ -154,6 +155,7 @@ func TestHotRegionStorageReservedDayConfigChange(t *testing.T) {
},
)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
re.NotEmpty(cluster.WaitLeader())
Expand All @@ -175,7 +177,7 @@ func TestHotRegionStorageReservedDayConfigChange(t *testing.T) {
for _, store := range stores {
tests.MustPutStore(re, cluster, store)
}
defer cluster.Destroy()

startTime := time.Now().Unix()
tests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetWrittenBytes(3000000000),
core.SetReportInterval(uint64(startTime-utils.RegionHeartBeatReportInterval), uint64(startTime)))
Expand Down Expand Up @@ -246,6 +248,7 @@ func TestHotRegionStorageWriteIntervalConfigChange(t *testing.T) {
},
)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
re.NotEmpty(cluster.WaitLeader())
Expand All @@ -267,7 +270,6 @@ func TestHotRegionStorageWriteIntervalConfigChange(t *testing.T) {
for _, store := range stores {
tests.MustPutStore(re, cluster, store)
}
defer cluster.Destroy()
startTime := time.Now().Unix()
tests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"),
core.SetWrittenBytes(3000000000),
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-backup/tests/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func TestBackup(t *testing.T) {
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
re.NotEmpty(cluster.WaitLeader())
leaderServer := cluster.GetLeaderServer()
leaderServer.BootstrapCluster()
pdAddr := cluster.GetConfig().GetClientURL()
urls := strings.Split(pdAddr, ",")
defer cluster.Destroy()
client, err := clientv3.New(clientv3.Config{
Endpoints: urls,
DialTimeout: 3 * time.Second,
Expand Down
7 changes: 2 additions & 5 deletions tools/pd-ctl/tests/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,10 @@ func (suite *keyspaceTestSuite) SetupTest() {

func (suite *keyspaceTestSuite) TearDownTest() {
re := suite.Require()
re.NoError(failpoint.Disable("github.com/tikv/pd/server/delayStartServerLoop"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/skipSplitRegion"))
}

func (suite *keyspaceTestSuite) TearDownSuite() {
suite.cancel()
suite.cluster.Destroy()
re.NoError(failpoint.Disable("github.com/tikv/pd/server/delayStartServerLoop"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/skipSplitRegion"))
}

func (suite *keyspaceTestSuite) TestShowKeyspace() {
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-ctl/tests/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestStoreLimitV2(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
re.NotEmpty(cluster.WaitLeader())
Expand All @@ -54,7 +55,6 @@ func TestStoreLimitV2(t *testing.T) {

leaderServer := cluster.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
defer cluster.Destroy()

// store command
args := []string{"-u", pdAddr, "config", "set", "store-limit-version", "v2"}
Expand Down
1 change: 0 additions & 1 deletion tools/pd-ctl/tests/unsafe/unsafe_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestRemoveFailedStores(t *testing.T) {
re.NoError(err)
pdAddr := cluster.GetConfig().GetClientURL()
cmd := ctl.GetRootCmd()
defer cluster.Destroy()

args := []string{"-u", pdAddr, "unsafe", "remove-failed-stores", "1,2,3"}
_, err = tests.ExecuteCommand(cmd, args...)
Expand Down
Loading