fix(process): capture health server in serve goroutine
This commit is contained in:
parent
f94b83fe6d
commit
e2f84b69e1
2 changed files with 11 additions and 4 deletions
|
|
@ -92,12 +92,13 @@ func (h *HealthServer) Start() error {
|
|||
return core.E("health.start", core.Concat("failed to listen on ", h.addr), err)
|
||||
}
|
||||
|
||||
server := &http.Server{Handler: mux}
|
||||
h.listener = listener
|
||||
h.server = &http.Server{Handler: mux}
|
||||
h.server = server
|
||||
|
||||
go func() {
|
||||
_ = h.server.Serve(listener)
|
||||
}()
|
||||
go func(srv *http.Server, ln net.Listener) {
|
||||
_ = srv.Serve(ln)
|
||||
}(server, listener)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,12 @@ func TestHealthServer_WithChecks_Good(t *testing.T) {
|
|||
_ = resp.Body.Close()
|
||||
}
|
||||
|
||||
func TestHealthServer_StopImmediately_Good(t *testing.T) {
|
||||
hs := NewHealthServer("127.0.0.1:0")
|
||||
require.NoError(t, hs.Start())
|
||||
require.NoError(t, hs.Stop(context.Background()))
|
||||
}
|
||||
|
||||
func TestWaitForHealth_Reachable_Good(t *testing.T) {
|
||||
hs := NewHealthServer("127.0.0.1:0")
|
||||
require.NoError(t, hs.Start())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue