Skip to content

Commit

Permalink
tests/tso: Create independent clients to prevent interfering with oth…
Browse files Browse the repository at this point in the history
…er tests. (#8546)

ref #8103

tests/tso: Create independent clients to prevent interfering with other tests.

Signed-off-by: husharp <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
HuSharp and ti-chi-bot[bot] authored Aug 20, 2024
1 parent a766351 commit 6bf980d
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,7 @@ func (suite *tsoClientTestSuite) SetupSuite() {
suite.backendEndpoints = suite.pdLeaderServer.GetAddr()
suite.keyspaceIDs = make([]uint32, 0)

if suite.legacy {
client, err := pd.NewClientWithContext(suite.ctx, suite.getBackendEndpoints(), pd.SecurityOption{}, pd.WithForwardingOption(true))
re.NoError(err)
innerClient, ok := client.(interface{ GetServiceDiscovery() pd.ServiceDiscovery })
re.True(ok)
re.Equal(constant.NullKeyspaceID, innerClient.GetServiceDiscovery().GetKeyspaceID())
re.Equal(constant.DefaultKeyspaceGroupID, innerClient.GetServiceDiscovery().GetKeyspaceGroupID())
mcs.WaitForTSOServiceAvailable(suite.ctx, re, client)
suite.clients = make([]pd.Client, 0)
suite.clients = append(suite.clients, client)
} else {
if !suite.legacy {
suite.tsoCluster, err = tests.NewTestTSOCluster(suite.ctx, 3, suite.backendEndpoints)
re.NoError(err)

Expand Down Expand Up @@ -148,7 +138,23 @@ func (suite *tsoClientTestSuite) SetupSuite() {
},
})
}
}
}

// Create independent clients to prevent interfering with other tests.
func (suite *tsoClientTestSuite) SetupTest() {
re := suite.Require()
if suite.legacy {
client, err := pd.NewClientWithContext(suite.ctx, suite.getBackendEndpoints(), pd.SecurityOption{}, pd.WithForwardingOption(true))
re.NoError(err)
innerClient, ok := client.(interface{ GetServiceDiscovery() pd.ServiceDiscovery })
re.True(ok)
re.Equal(constant.NullKeyspaceID, innerClient.GetServiceDiscovery().GetKeyspaceID())
re.Equal(constant.DefaultKeyspaceGroupID, innerClient.GetServiceDiscovery().GetKeyspaceGroupID())
mcs.WaitForTSOServiceAvailable(suite.ctx, re, client)
suite.clients = make([]pd.Client, 0)
suite.clients = append(suite.clients, client)
} else {
suite.waitForAllKeyspaceGroupsInServing(re)
}
}
Expand Down Expand Up @@ -183,15 +189,18 @@ func (suite *tsoClientTestSuite) waitForAllKeyspaceGroupsInServing(re *require.A
re.Equal(len(suite.keyspaceIDs), len(suite.clients))
}

func (suite *tsoClientTestSuite) TearDownTest() {
for _, client := range suite.clients {
client.Close()
}
}

func (suite *tsoClientTestSuite) TearDownSuite() {
suite.cancel()
if !suite.legacy {
suite.tsoCluster.Destroy()
}
suite.cluster.Destroy()
for _, client := range suite.clients {
client.Close()
}
}

func (suite *tsoClientTestSuite) TestGetTS() {
Expand Down Expand Up @@ -432,21 +441,13 @@ func (suite *tsoClientTestSuite) TestGetTSWhileResettingTSOClient() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/client/delayDispatchTSORequest", "return(true)"))
var (
clients []pd.Client
stopSignal atomic.Bool
wg sync.WaitGroup
)
// Create independent clients to prevent interfering with other tests.
if suite.legacy {
client, err := pd.NewClientWithContext(suite.ctx, suite.getBackendEndpoints(), pd.SecurityOption{}, pd.WithForwardingOption(true))
re.NoError(err)
clients = []pd.Client{client}
} else {
clients = mcs.WaitForMultiKeyspacesTSOAvailable(suite.ctx, re, suite.keyspaceIDs, suite.getBackendEndpoints())
}
wg.Add(tsoRequestConcurrencyNumber * len(clients))

wg.Add(tsoRequestConcurrencyNumber * len(suite.clients))
for i := 0; i < tsoRequestConcurrencyNumber; i++ {
for _, client := range clients {
for _, client := range suite.clients {
go func(client pd.Client) {
defer wg.Done()
var lastTS uint64
Expand All @@ -465,7 +466,7 @@ func (suite *tsoClientTestSuite) TestGetTSWhileResettingTSOClient() {
}
// Reset the TSO clients while requesting TSO concurrently.
for i := 0; i < tsoRequestConcurrencyNumber; i++ {
for _, client := range clients {
for _, client := range suite.clients {
client.(interface{ ResetTSOClient() }).ResetTSOClient()
}
}
Expand Down

0 comments on commit 6bf980d

Please sign in to comment.