ceremonyclient/go-libp2p/p2p/host/resource-manager/stats_test.go
2023-08-20 23:07:43 -05:00

40 lines
723 B
Go

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)
}