Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#51595
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
shenqidebaozi authored and ti-chi-bot committed Mar 8, 2024
1 parent b244b1b commit d3abb52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,13 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
concurrentLimiter: NewTokenLimiter(cfg.TokenLimit),
clients: make(map[uint64]*clientConn),
ConnNumByResourceGroup: make(map[string]int),
<<<<<<< HEAD
internalSessions: make(map[interface{}]struct{}, 100),
health: uatomic.NewBool(true),
=======
internalSessions: make(map[any]struct{}, 100),
health: uatomic.NewBool(false),
>>>>>>> d3a9c1b8677 (server: fix incorrect setting of health status (#51595))
inShutdownMode: uatomic.NewBool(false),
printMDLLogTime: time.Now(),
}
Expand Down Expand Up @@ -435,7 +440,15 @@ func (s *Server) Run(dom *domain.Domain) error {
errChan := make(chan error, 2)
go s.startNetworkListener(s.listener, false, errChan)
go s.startNetworkListener(s.socket, true, errChan)
<<<<<<< HEAD
err := <-errChan
=======
if RunInGoTest && !isClosed(RunInGoTestChan) {
close(RunInGoTestChan)
}
s.health.Store(true)
err = <-errChan
>>>>>>> d3a9c1b8677 (server: fix incorrect setting of health status (#51595))
if err != nil {
return err
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,25 @@ func TestGetConAttrs(t *testing.T) {
_, hasClientName = attrs[1]
require.False(t, hasClientName)
}

func TestSeverHealth(t *testing.T) {
RunInGoTestChan = make(chan struct{})
RunInGoTest = true
store := testkit.CreateMockStore(t)
tidbdrv := NewTiDBDriver(store)
cfg := util.NewTestConfig()
cfg.Port, cfg.Status.StatusPort = 0, 0
cfg.Status.ReportStatus = false
server, err := NewServer(cfg, tidbdrv)
require.NoError(t, err)
require.False(t, server.health.Load(), "server should not be healthy")
go func() {
err = server.Run(nil)
require.NoError(t, err)
}()
defer server.Close()
for range RunInGoTestChan {
// wait for server to be healthy
}
require.True(t, server.health.Load(), "server should be healthy")
}

0 comments on commit d3abb52

Please sign in to comment.