Skip to content

Commit fd25746

Browse files
Revert "Fix flaky TestMetricsNoAllocNoCover test (#2142)"
This reverts commit cbcdd79.
1 parent 30cdb2e commit fd25746

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

p2p/protocol/identify/id.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ type IDService interface {
8181
io.Closer
8282
}
8383

84-
type IdentifyPushSupport uint8
84+
type identifyPushSupport uint8
8585

8686
const (
87-
IdentifyPushSupportUnknown IdentifyPushSupport = iota
88-
IdentifyPushSupported
89-
IdentifyPushUnsupported
87+
identifyPushSupportUnknown identifyPushSupport = iota
88+
identifyPushSupported
89+
identifyPushUnsupported
9090
)
9191

9292
type entry struct {
@@ -96,7 +96,7 @@ type entry struct {
9696

9797
// PushSupport saves our knowledge about the peer's support of the Identify Push protocol.
9898
// Before the identify request returns, we don't know yet if the peer supports Identify Push.
99-
PushSupport IdentifyPushSupport
99+
PushSupport identifyPushSupport
100100
// Sequence is the sequence number of the last snapshot we sent to this peer.
101101
Sequence uint64
102102
}
@@ -271,7 +271,7 @@ func (ids *idService) sendPushes(ctx context.Context) {
271271
for c, e := range ids.conns {
272272
// Push even if we don't know if push is supported.
273273
// This will be only the case while the IdentifyWaitChan call is in flight.
274-
if e.PushSupport == IdentifyPushSupported || e.PushSupport == IdentifyPushSupportUnknown {
274+
if e.PushSupport == identifyPushSupported || e.PushSupport == identifyPushSupportUnknown {
275275
conns = append(conns, c)
276276
}
277277
}
@@ -496,9 +496,9 @@ func (ids *idService) handleIdentifyResponse(s network.Stream, isPush bool) erro
496496
}
497497
sup, err := ids.Host.Peerstore().SupportsProtocols(c.RemotePeer(), IDPush)
498498
if supportsIdentifyPush := err == nil && len(sup) > 0; supportsIdentifyPush {
499-
e.PushSupport = IdentifyPushSupported
499+
e.PushSupport = identifyPushSupported
500500
} else {
501-
e.PushSupport = IdentifyPushUnsupported
501+
e.PushSupport = identifyPushUnsupported
502502
}
503503

504504
if ids.metricsTracer != nil {

p2p/protocol/identify/metrics.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type MetricsTracer interface {
9595
TriggeredPushes(event any)
9696

9797
// ConnPushSupport counts peers by Push Support
98-
ConnPushSupport(IdentifyPushSupport)
98+
ConnPushSupport(identifyPushSupport)
9999

100100
// IdentifyReceived tracks metrics on receiving an identify response
101101
IdentifyReceived(isPush bool, numProtocols int, numAddrs int)
@@ -146,7 +146,7 @@ func (t *metricsTracer) TriggeredPushes(ev any) {
146146
pushesTriggered.WithLabelValues(*tags...).Inc()
147147
}
148148

149-
func (t *metricsTracer) IncrementPushSupport(s IdentifyPushSupport) {
149+
func (t *metricsTracer) IncrementPushSupport(s identifyPushSupport) {
150150
tags := metricshelper.GetStringSlice()
151151
defer metricshelper.PutStringSlice(tags)
152152

@@ -186,19 +186,19 @@ func (t *metricsTracer) IdentifyReceived(isPush bool, numProtocols int, numAddrs
186186
numAddrsReceived.Observe(float64(numAddrs))
187187
}
188188

189-
func (t *metricsTracer) ConnPushSupport(support IdentifyPushSupport) {
189+
func (t *metricsTracer) ConnPushSupport(support identifyPushSupport) {
190190
tags := metricshelper.GetStringSlice()
191191
defer metricshelper.PutStringSlice(tags)
192192

193193
*tags = append(*tags, getPushSupport(support))
194194
connPushSupportTotal.WithLabelValues(*tags...).Inc()
195195
}
196196

197-
func getPushSupport(s IdentifyPushSupport) string {
197+
func getPushSupport(s identifyPushSupport) string {
198198
switch s {
199-
case IdentifyPushSupported:
199+
case identifyPushSupported:
200200
return "supported"
201-
case IdentifyPushUnsupported:
201+
case identifyPushUnsupported:
202202
return "not supported"
203203
default:
204204
return "unknown"

p2p/protocol/identify/metrics_alloc_test/metrics_test.go renamed to p2p/protocol/identify/metrics_test.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
//go:build nocover
22

3-
// These tests are in their own package to avoid transitively pulling in other
4-
// deps that may run background tasks in their init and thus allocate. Looking
5-
// at you
6-
// [go-libp2p-asn-util](https://github.com/libp2p/go-libp2p-asn-util/blob/master/asn.go#L14)
7-
8-
package identify_alloc_test
3+
package identify
94

105
import (
116
"math/rand"
127
"testing"
138

149
"github.com/libp2p/go-libp2p/core/event"
15-
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
1610
)
1711

1812
func TestMetricsNoAllocNoCover(t *testing.T) {
@@ -22,20 +16,19 @@ func TestMetricsNoAllocNoCover(t *testing.T) {
2216
event.EvtNATDeviceTypeChanged{},
2317
}
2418

25-
pushSupport := []identify.IdentifyPushSupport{
26-
identify.IdentifyPushSupportUnknown,
27-
identify.IdentifyPushSupported,
28-
identify.IdentifyPushUnsupported,
19+
pushSupport := []identifyPushSupport{
20+
identifyPushSupportUnknown,
21+
identifyPushSupported,
22+
identifyPushUnsupported,
2923
}
3024

31-
tr := identify.NewMetricsTracer()
25+
tr := NewMetricsTracer()
3226
tests := map[string]func(){
3327
"TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) },
3428
"ConnPushSupport": func() { tr.ConnPushSupport(pushSupport[rand.Intn(len(pushSupport))]) },
3529
"IdentifyReceived": func() { tr.IdentifyReceived(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) },
3630
"IdentifySent": func() { tr.IdentifySent(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) },
3731
}
38-
3932
for method, f := range tests {
4033
allocs := testing.AllocsPerRun(1000, f)
4134
if allocs > 0 {

0 commit comments

Comments
 (0)