mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-24 16:20:23 +08:00
fix tests that involve HTTP clients
This commit is contained in:
@@ -270,8 +270,8 @@ func newAPI(
|
|||||||
|
|
||||||
func (a *api) close() {
|
func (a *api) close() {
|
||||||
a.log(logger.Info, "listener is closing")
|
a.log(logger.Info, "listener is closing")
|
||||||
a.ln.Close() // in case Shutdown() is called before Serve()
|
|
||||||
a.s.Shutdown(context.Background())
|
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{}) {
|
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) {
|
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")
|
p, ok := newInstance("api: yes\n")
|
||||||
require.Equal(t, true, ok)
|
require.Equal(t, true, ok)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|||||||
@@ -248,8 +248,8 @@ outer:
|
|||||||
|
|
||||||
s.ctxCancel()
|
s.ctxCancel()
|
||||||
|
|
||||||
s.ln.Close() // in case Shutdown() is called before Serve()
|
|
||||||
hs.Shutdown(context.Background())
|
hs.Shutdown(context.Background())
|
||||||
|
s.ln.Close() // in case Shutdown() is called before Serve()
|
||||||
|
|
||||||
s.pathManager.hlsServerSet(nil)
|
s.pathManager.hlsServerSet(nil)
|
||||||
|
|
||||||
|
|||||||
@@ -72,25 +72,21 @@ func newMetrics(
|
|||||||
|
|
||||||
m.log(logger.Info, "listener opened on "+address)
|
m.log(logger.Info, "listener opened on "+address)
|
||||||
|
|
||||||
go m.run()
|
go m.server.Serve(m.ln)
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *metrics) close() {
|
func (m *metrics) close() {
|
||||||
m.log(logger.Info, "listener is closing")
|
m.log(logger.Info, "listener is closing")
|
||||||
m.ln.Close() // in case Shutdown() is called before Serve()
|
|
||||||
m.server.Shutdown(context.Background())
|
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{}) {
|
func (m *metrics) log(level logger.Level, format string, args ...interface{}) {
|
||||||
m.parent.Log(level, "[metrics] "+format, args...)
|
m.parent.Log(level, "[metrics] "+format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *metrics) run() {
|
|
||||||
m.server.Serve(m.ln)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *metrics) onMetrics(ctx *gin.Context) {
|
func (m *metrics) onMetrics(ctx *gin.Context) {
|
||||||
out := ""
|
out := ""
|
||||||
|
|
||||||
|
|||||||
@@ -42,21 +42,17 @@ func newPPROF(
|
|||||||
|
|
||||||
pp.log(logger.Info, "listener opened on "+address)
|
pp.log(logger.Info, "listener opened on "+address)
|
||||||
|
|
||||||
go pp.run()
|
go pp.server.Serve(pp.ln)
|
||||||
|
|
||||||
return pp, nil
|
return pp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *pprof) close() {
|
func (pp *pprof) close() {
|
||||||
pp.log(logger.Info, "listener is closing")
|
pp.log(logger.Info, "listener is closing")
|
||||||
pp.ln.Close() // in case Shutdown() is called before Serve()
|
|
||||||
pp.server.Shutdown(context.Background())
|
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{}) {
|
func (pp *pprof) log(level logger.Level, format string, args ...interface{}) {
|
||||||
pp.parent.Log(level, "[pprof] "+format, args...)
|
pp.parent.Log(level, "[pprof] "+format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *pprof) run() {
|
|
||||||
pp.server.Serve(pp.ln)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user