Skip to content

Commit 5950ba3

Browse files
Simplify gossip tests (#4547)
1 parent a02fd12 commit 5950ba3

File tree

5 files changed

+171
-266
lines changed

5 files changed

+171
-266
lines changed

network/p2p/gossip/bloom_test.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/prometheus/client_golang/prometheus/testutil"
1212
"github.com/stretchr/testify/require"
13-
14-
"github.com/ava-labs/avalanchego/ids"
1513
)
1614

1715
func TestBloomFilterRefresh(t *testing.T) {
@@ -21,24 +19,24 @@ func TestBloomFilterRefresh(t *testing.T) {
2119
targetFalsePositiveProbability float64
2220
resetFalsePositiveProbability float64
2321
resetCount uint64
24-
add []*testTx
25-
expected []*testTx
22+
add []tx
23+
expected []tx
2624
}{
2725
{
2826
name: "no refresh",
2927
minTargetElements: 1,
3028
targetFalsePositiveProbability: 0.01,
3129
resetFalsePositiveProbability: 1,
3230
resetCount: 0, // maxCount = 9223372036854775807
33-
add: []*testTx{
34-
{id: ids.ID{0}},
35-
{id: ids.ID{1}},
36-
{id: ids.ID{2}},
31+
add: []tx{
32+
{0},
33+
{1},
34+
{2},
3735
},
38-
expected: []*testTx{
39-
{id: ids.ID{0}},
40-
{id: ids.ID{1}},
41-
{id: ids.ID{2}},
36+
expected: []tx{
37+
{0},
38+
{1},
39+
{2},
4240
},
4341
},
4442
{
@@ -47,13 +45,13 @@ func TestBloomFilterRefresh(t *testing.T) {
4745
targetFalsePositiveProbability: 0.01,
4846
resetFalsePositiveProbability: 0.0000000000000001, // maxCount = 1
4947
resetCount: 1,
50-
add: []*testTx{
51-
{id: ids.ID{0}},
52-
{id: ids.ID{1}},
53-
{id: ids.ID{2}},
48+
add: []tx{
49+
{0},
50+
{1},
51+
{2},
5452
},
55-
expected: []*testTx{
56-
{id: ids.ID{2}},
53+
expected: []tx{
54+
{2},
5755
},
5856
},
5957
{
@@ -62,15 +60,15 @@ func TestBloomFilterRefresh(t *testing.T) {
6260
targetFalsePositiveProbability: 0.01,
6361
resetFalsePositiveProbability: 0.0000000000000001, // maxCount = 1
6462
resetCount: 2,
65-
add: []*testTx{
66-
{id: ids.ID{0}},
67-
{id: ids.ID{1}},
68-
{id: ids.ID{2}},
69-
{id: ids.ID{3}},
70-
{id: ids.ID{4}},
63+
add: []tx{
64+
{0},
65+
{1},
66+
{2},
67+
{3},
68+
{4},
7169
},
72-
expected: []*testTx{
73-
{id: ids.ID{4}},
70+
expected: []tx{
71+
{4},
7472
},
7573
},
7674
}

network/p2p/gossip/gossip.go

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/ava-labs/avalanchego/ids"
1919
"github.com/ava-labs/avalanchego/network/p2p"
2020
"github.com/ava-labs/avalanchego/snow/engine/common"
21-
"github.com/ava-labs/avalanchego/utils/bloom"
2221
"github.com/ava-labs/avalanchego/utils/buffer"
2322
"github.com/ava-labs/avalanchego/utils/logging"
2423
"github.com/ava-labs/avalanchego/utils/set"
@@ -40,10 +39,7 @@ const (
4039

4140
var (
4241
_ Gossiper = (*ValidatorGossiper)(nil)
43-
_ Gossiper = (*PullGossiper[*testTx])(nil)
44-
_ Gossiper = (*NoOpGossiper)(nil)
45-
46-
_ Set[*testTx] = (*FullSet[*testTx])(nil)
42+
_ Gossiper = (*PullGossiper[Gossipable])(nil)
4743

4844
ioTypeLabels = []string{ioLabel, typeLabel}
4945
sentPushLabels = prometheus.Labels{
@@ -597,37 +593,3 @@ func Every(ctx context.Context, log logging.Logger, gossiper Gossiper, frequency
597593
}
598594
}
599595
}
600-
601-
type NoOpGossiper struct{}
602-
603-
func (NoOpGossiper) Gossip(context.Context) error {
604-
return nil
605-
}
606-
607-
type TestGossiper struct {
608-
GossipF func(ctx context.Context) error
609-
}
610-
611-
func (t *TestGossiper) Gossip(ctx context.Context) error {
612-
return t.GossipF(ctx)
613-
}
614-
615-
type FullSet[T Gossipable] struct{}
616-
617-
func (FullSet[_]) Gossip(context.Context) error {
618-
return nil
619-
}
620-
621-
func (FullSet[T]) Add(T) error {
622-
return nil
623-
}
624-
625-
func (FullSet[T]) Has(ids.ID) bool {
626-
return true
627-
}
628-
629-
func (FullSet[T]) Iterate(func(gossipable T) bool) {}
630-
631-
func (FullSet[_]) GetFilter() ([]byte, []byte) {
632-
return bloom.FullFilter.Marshal(), ids.Empty[:]
633-
}

0 commit comments

Comments
 (0)