mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-11-15 20:55:17 +00:00
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
|
//go:build nocover
|
||
|
|
||
|
package identify
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/libp2p/go-libp2p/core/event"
|
||
|
)
|
||
|
|
||
|
func TestMetricsNoAllocNoCover(t *testing.T) {
|
||
|
events := []any{
|
||
|
event.EvtLocalAddressesUpdated{},
|
||
|
event.EvtLocalProtocolsUpdated{},
|
||
|
event.EvtNATDeviceTypeChanged{},
|
||
|
}
|
||
|
|
||
|
pushSupport := []identifyPushSupport{
|
||
|
identifyPushSupportUnknown,
|
||
|
identifyPushSupported,
|
||
|
identifyPushUnsupported,
|
||
|
}
|
||
|
|
||
|
tr := NewMetricsTracer()
|
||
|
tests := map[string]func(){
|
||
|
"TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) },
|
||
|
"ConnPushSupport": func() { tr.ConnPushSupport(pushSupport[rand.Intn(len(pushSupport))]) },
|
||
|
"IdentifyReceived": func() { tr.IdentifyReceived(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) },
|
||
|
"IdentifySent": func() { tr.IdentifySent(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) },
|
||
|
}
|
||
|
for method, f := range tests {
|
||
|
allocs := testing.AllocsPerRun(1000, f)
|
||
|
if allocs > 0 {
|
||
|
t.Fatalf("Alloc Test: %s, got: %0.2f, expected: 0 allocs", method, allocs)
|
||
|
}
|
||
|
}
|
||
|
}
|