mirror of https://github.com/status-im/go-waku.git
test: Add metrics unit test
This commit is contained in:
parent
4227a9d69d
commit
990bbc50dc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue