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

*: fix TestMixedTSODeployment case #6312

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion client/pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ func (c *pdServiceDiscovery) updateMemberLoop() {
}

func (c *pdServiceDiscovery) updateServiceModeLoop() {
defer c.wg.Done()
failpoint.Inject("skipUpdateServiceMode", func() {
failpoint.Return()
})
defer c.wg.Done()

ctx, cancel := context.WithCancel(c.ctx)
defer cancel()
Expand Down
5 changes: 2 additions & 3 deletions pkg/mcs/resource_manager/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ func (s *Server) startHTTPServer(l net.Listener) {

handler, _ := SetUpRestHandler(s.service)
hs := &http.Server{
Handler: handler,
ReadTimeout: 5 * time.Minute,
ReadHeaderTimeout: 5 * time.Second,
Handler: handler,
ReadTimeout: 5 * time.Second,
}
err := hs.Serve(l)
log.Info("http server stop serving")
Expand Down
7 changes: 3 additions & 4 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *Server) Close() {
return
}

log.Info("closing tso server ...")
log.Info("closing tso server")
// close tso service loops in the keyspace group manager
s.keyspaceGroupManager.Close()
s.serviceRegister.Deregister()
Expand Down Expand Up @@ -377,9 +377,8 @@ func (s *Server) startHTTPServer(l net.Listener) {

handler, _ := SetUpRestHandler(s.service)
hs := &http.Server{
Handler: handler,
ReadTimeout: 5 * time.Minute,
ReadHeaderTimeout: 5 * time.Second,
Handler: handler,
ReadTimeout: 5 * time.Second,
}
serverr := hs.Serve(l)
log.Info("http server stopped serving")
Expand Down
31 changes: 19 additions & 12 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (suite *tsoClientTestSuite) TestRandomTransferLeader() {
ctx, cancel := context.WithCancel(suite.ctx)
var wg sync.WaitGroup
wg.Add(tsoRequestConcurrencyNumber + 1)
checkTSO(ctx, re, &wg, suite.backendEndpoints)
go func() {
defer wg.Done()
n := r.Intn(2) + 1
Expand All @@ -195,7 +196,6 @@ func (suite *tsoClientTestSuite) TestRandomTransferLeader() {
cancel()
}()

checkTSO(ctx, re, &wg, suite.backendEndpoints)
wg.Wait()
}

Expand All @@ -210,6 +210,7 @@ func (suite *tsoClientTestSuite) TestRandomShutdown() {
ctx, cancel := context.WithCancel(suite.ctx)
var wg sync.WaitGroup
wg.Add(tsoRequestConcurrencyNumber + 1)
checkTSO(ctx, re, &wg, suite.backendEndpoints)
go func() {
defer wg.Done()
r := rand.New(rand.NewSource(time.Now().UnixNano()))
Expand All @@ -229,7 +230,6 @@ func (suite *tsoClientTestSuite) TestRandomShutdown() {
cancel()
}()

checkTSO(ctx, re, &wg, suite.backendEndpoints)
wg.Wait()
suite.TearDownSuite()
suite.SetupSuite()
Expand All @@ -245,26 +245,29 @@ func TestMixedTSODeployment(t *testing.T) {
defer re.NoError(failpoint.Enable("github.com/tikv/pd/client/skipUpdateServiceMode", "return(true)"))

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()
re.NoError(err)

leaderServer := cluster.GetServer(cluster.WaitLeader())
backendEndpoints := leaderServer.GetAddr()
re.NoError(leaderServer.BootstrapCluster())

apiSvr, err := cluster.JoinAPIServer(ctx)
re.NoError(err)
err = apiSvr.Run()
re.NoError(err)

var backendEndpoints string
for _, s := range cluster.GetServers() {
backendEndpoints += s.GetAddr() + ","
}
backendEndpoints = strings.TrimSuffix(backendEndpoints, ",")
_, cleanup := mcs.StartSingleTSOTestServer(ctx, re, backendEndpoints, tempurl.Alloc())
defer cleanup()

ctx1, cancel1 := context.WithCancel(context.Background())
ctx1, cancel1 := context.WithCancel(ctx)
var wg sync.WaitGroup
wg.Add(tsoRequestConcurrencyNumber + 1)
go func() {
Expand All @@ -284,9 +287,10 @@ func TestMixedTSODeployment(t *testing.T) {

func checkTSO(ctx context.Context, re *require.Assertions, wg *sync.WaitGroup, backendEndpoints string) {
for i := 0; i < tsoRequestConcurrencyNumber; i++ {
go func() {
go func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
cli := mcs.SetupClientWithKeyspace(context.Background(), re, strings.Split(backendEndpoints, ","))
defer cli.Close()
var ts, lastTS uint64
for {
physical, logical, err := cli.GetTS(context.Background())
Expand All @@ -298,13 +302,16 @@ func checkTSO(ctx context.Context, re *require.Assertions, wg *sync.WaitGroup, b
}
select {
case <-ctx.Done():
physical, logical, _ := cli.GetTS(context.Background())
ts = tsoutil.ComposeTS(physical, logical)
re.Less(lastTS, ts)
physical, logical, err := cli.GetTS(context.Background())
// omit the error check since there are many kinds of errors
if err == nil {
ts = tsoutil.ComposeTS(physical, logical)
re.Less(lastTS, ts)
}
return
default:
}
}
}()
}(ctx, wg)
}
}