mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-13 09:58:50 +00:00
fix tests that involve HTTP clients
This commit is contained in:
parent
f25e14183d
commit
a8d1f91646
@ -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{}) {
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 := ""
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user