Skip to content

Commit

Permalink
server: fix incorrect setting of health status (#51595)
Browse files Browse the repository at this point in the history
close #51596
  • Loading branch information
shenqidebaozi committed Mar 8, 2024
1 parent bc84197 commit d3a9c1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
clients: make(map[uint64]*clientConn),
ConnNumByResourceGroup: make(map[string]int),
internalSessions: make(map[any]struct{}, 100),
health: uatomic.NewBool(true),
health: uatomic.NewBool(false),
inShutdownMode: uatomic.NewBool(false),
printMDLLogTime: time.Now(),
}
Expand Down Expand Up @@ -459,6 +459,7 @@ func (s *Server) Run(dom *domain.Domain) error {
if RunInGoTest && !isClosed(RunInGoTestChan) {
close(RunInGoTestChan)
}
s.health.Store(true)
err = <-errChan
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 d3a9c1b

Please sign in to comment.