fix tests that involve HTTP clients

This commit is contained in:
aler9 2022-08-31 08:53:05 +02:00
parent f25e14183d
commit a8d1f91646
5 changed files with 10 additions and 14 deletions

View File

@ -270,8 +270,8 @@ func newAPI(
func (a *api) close() {
a.log(logger.Info, "listener is closing")
a.ln.Close() // in case Shutdown() is called before Serve()
a.s.Shutdown(context.Background())
a.ln.Close() // in case Shutdown() is called before Serve()
}
func (a *api) log(level logger.Level, format string, args ...interface{}) {

View File

@ -60,6 +60,10 @@ func httpRequest(method string, ur string, in interface{}, out interface{}) erro
}
func TestAPIConfigGet(t *testing.T) {
// since the HTTP server is created and deleted multiple times,
// we can't reuse TCP connections.
http.DefaultTransport.(*http.Transport).DisableKeepAlives = true
p, ok := newInstance("api: yes\n")
require.Equal(t, true, ok)
defer p.close()

View File

@ -248,8 +248,8 @@ outer:
s.ctxCancel()
s.ln.Close() // in case Shutdown() is called before Serve()
hs.Shutdown(context.Background())
s.ln.Close() // in case Shutdown() is called before Serve()
s.pathManager.hlsServerSet(nil)

View File

@ -72,25 +72,21 @@ func newMetrics(
m.log(logger.Info, "listener opened on "+address)
go m.run()
go m.server.Serve(m.ln)
return m, nil
}
func (m *metrics) close() {
m.log(logger.Info, "listener is closing")
m.ln.Close() // in case Shutdown() is called before Serve()
m.server.Shutdown(context.Background())
m.ln.Close() // in case Shutdown() is called before Serve()
}
func (m *metrics) log(level logger.Level, format string, args ...interface{}) {
m.parent.Log(level, "[metrics] "+format, args...)
}
func (m *metrics) run() {
m.server.Serve(m.ln)
}
func (m *metrics) onMetrics(ctx *gin.Context) {
out := ""

View File

@ -42,21 +42,17 @@ func newPPROF(
pp.log(logger.Info, "listener opened on "+address)
go pp.run()
go pp.server.Serve(pp.ln)
return pp, nil
}
func (pp *pprof) close() {
pp.log(logger.Info, "listener is closing")
pp.ln.Close() // in case Shutdown() is called before Serve()
pp.server.Shutdown(context.Background())
pp.ln.Close() // in case Shutdown() is called before Serve()
}
func (pp *pprof) log(level logger.Level, format string, args ...interface{}) {
pp.parent.Log(level, "[pprof] "+format, args...)
}
func (pp *pprof) run() {
pp.server.Serve(pp.ln)
}