e2e: fix trace_sync http handler registration (#9644)

* Avoid a global http server so that multiple test runs aren't registering global http handlers and causing a panic

* gofmt
This commit is contained in:
Preston Van Loon
2021-09-21 23:34:09 -04:00
committed by GitHub
parent 8e3e6d0156
commit 36a7575437

View File

@@ -52,7 +52,11 @@ func (ts *TracingSink) Started() <-chan struct{} {
// Initialize an http handler that writes all requests to a file.
func (ts *TracingSink) initializeSink() {
ts.server = &http.Server{Addr: ts.endpoint}
mux := &http.ServeMux{}
ts.server = &http.Server{
Addr: ts.endpoint,
Handler: mux,
}
defer func() {
if err := ts.server.Close(); err != nil {
log.WithError(err).Error("Failed to close http server")
@@ -69,8 +73,7 @@ func (ts *TracingSink) initializeSink() {
log.WithError(err).Error("Could not close stdout file")
}
}
http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
if err := captureRequest(stdOutFile, r); err != nil {
log.WithError(err).Error("Failed to capture http request")
return