Fix P2P Test (#10157)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das 2022-01-31 20:23:25 +08:00 committed by GitHub
parent 98470fdb13
commit ce712a1a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,13 +278,13 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
}
}()
ps1, err := pubsub.NewFloodSub(context.Background(), hosts[0],
ps1, err := pubsub.NewGossipSub(context.Background(), hosts[0],
pubsub.WithMessageSigning(false),
pubsub.WithStrictSignatureVerification(false),
)
require.NoError(t, err)
ps2, err := pubsub.NewFloodSub(context.Background(), hosts[1],
ps2, err := pubsub.NewGossipSub(context.Background(), hosts[1],
pubsub.WithMessageSigning(false),
pubsub.WithStrictSignatureVerification(false),
)
@ -295,7 +295,7 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
pubsub: ps1,
dv5Listener: listeners[0],
joinedTopics: map[string]*pubsub.Topic{},
cfg: &Config{},
cfg: cfg,
genesisTime: time.Now(),
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
subnetsLock: make(map[uint64]*sync.RWMutex),
@ -311,7 +311,7 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
pubsub: ps2,
dv5Listener: listeners[1],
joinedTopics: map[string]*pubsub.Topic{},
cfg: &Config{},
cfg: cfg,
genesisTime: time.Now(),
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
subnetsLock: make(map[uint64]*sync.RWMutex),
@ -320,6 +320,8 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
ScorerParams: &scorers.Config{},
}),
}
go p.listenForNewNodes()
go p2.listenForNewNodes()
msg := util.HydrateAttestation(&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(7)})
topic := AttestationSubnetTopicFormat
@ -337,7 +339,18 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
sub, err := tpHandle.Subscribe()
require.NoError(t, err)
time.Sleep(50 * time.Millisecond) // libp2p fails without this delay...
tpHandle, err = p.JoinTopic(topic)
require.NoError(t, err)
_, err = tpHandle.Subscribe()
require.NoError(t, err)
time.Sleep(500 * time.Millisecond) // libp2p fails without this delay...
peers := p.pubsub.ListPeers(topic)
peers2 := p2.pubsub.ListPeers(topic)
assert.Equal(t, 1, len(peers))
assert.Equal(t, 1, len(peers2))
// Async listen for the pubsub, must be before the broadcast.
var wg sync.WaitGroup