diff --git a/waku/metrics/http.go b/waku/metrics/http.go index ae376931..d62bc706 100644 --- a/waku/metrics/http.go +++ b/waku/metrics/http.go @@ -69,13 +69,16 @@ func NewMetricsServer(address string, port int) *Server { // Start executes the HTTP server in the background. func (p *Server) Start() { - log.Info("Server stopped ", p.server.ListenAndServe()) + log.Info("server stopped ", p.server.ListenAndServe()) } // Stop shuts down the prometheus server -func (p *Server) Stop(ctx context.Context) { +func (p *Server) Stop(ctx context.Context) error { err := p.server.Shutdown(ctx) if err != nil { - log.Error("Server shutdown err", err) + log.Error("error while stopping server", err) + return err } + + return nil } diff --git a/waku/metrics/http_test.go b/waku/metrics/http_test.go new file mode 100644 index 00000000..9600bbcf --- /dev/null +++ b/waku/metrics/http_test.go @@ -0,0 +1,21 @@ +package metrics + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestStartAndStopMetricsServer(t *testing.T) { + server := NewMetricsServer("0.0.0.0", 9876) + + go func() { + time.Sleep(1 * time.Second) + err := server.Stop(context.Background()) + require.NoError(t, err) + }() + + server.Start() +} diff --git a/waku/node.go b/waku/node.go index 42073b72..013d9e89 100644 --- a/waku/node.go +++ b/waku/node.go @@ -233,7 +233,8 @@ func Execute(options Options) { wakuNode.Stop() if options.Metrics.Enable { - metricsServer.Stop(ctx) + err = metricsServer.Stop(ctx) + failOnErr(err, "MetricsClose") } if options.UseDB {