ceremonyclient/go-libp2p/p2p/host/resource-manager/stats_test.go

40 lines
723 B
Go
Raw Normal View History

2023-08-21 03:50:38 +00:00
package rcmgr
import (
"sync"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
)
var registerOnce sync.Once
func TestTraceReporterStartAndClose(t *testing.T) {
rcmgr, err := NewResourceManager(NewFixedLimiter(DefaultLimits.AutoScale()), WithTraceReporter(StatsTraceReporter{}))
if err != nil {
t.Fatal(err)
}
defer rcmgr.Close()
}
func TestConsumeEvent(t *testing.T) {
evt := TraceEvt{
Type: TraceBlockAddStreamEvt,
Name: "conn-1",
DeltaOut: 1,
Time: time.Now().Format(time.RFC3339Nano),
}
registerOnce.Do(func() {
MustRegisterWith(prometheus.DefaultRegisterer)
})
str, err := NewStatsTraceReporter()
if err != nil {
t.Fatal(err)
}
str.ConsumeEvent(evt)
}