attempting to fix discovery test flakeyness

This commit is contained in:
james-prysm
2025-11-04 23:10:23 -06:00
parent 8c701bf3b9
commit 3c76525870

View File

@@ -136,7 +136,6 @@ func setNodeSubnets(localNode *enode.LocalNode, attSubnets []uint64) {
} }
func TestCreateListener(t *testing.T) { func TestCreateListener(t *testing.T) {
port := 1024
ipAddr, pkey := createAddrAndPrivKey(t) ipAddr, pkey := createAddrAndPrivKey(t)
db := testDB.SetupDB(t) db := testDB.SetupDB(t)
@@ -147,7 +146,7 @@ func TestCreateListener(t *testing.T) {
ctx: t.Context(), ctx: t.Context(),
genesisTime: time.Now(), genesisTime: time.Now(),
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32), genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
cfg: &Config{UDPPort: uint(port), DB: db}, cfg: &Config{UDPPort: 0, DB: db}, // Use port 0 to let OS assign an available port
custodyInfo: &custodyInfo{}, custodyInfo: &custodyInfo{},
custodyInfoSet: custodyInfoSet, custodyInfoSet: custodyInfoSet,
} }
@@ -156,7 +155,6 @@ func TestCreateListener(t *testing.T) {
defer listener.Close() defer listener.Close()
assert.Equal(t, true, listener.Self().IP().Equal(ipAddr), "IP address is not the expected type") assert.Equal(t, true, listener.Self().IP().Equal(ipAddr), "IP address is not the expected type")
assert.Equal(t, port, listener.Self().UDP(), "Incorrect port number")
pubkey := listener.Self().Pubkey() pubkey := listener.Self().Pubkey()
XisSame := pkey.PublicKey.X.Cmp(pubkey.X) == 0 XisSame := pkey.PublicKey.X.Cmp(pubkey.X) == 0
@@ -365,7 +363,6 @@ func TestCreateLocalNode(t *testing.T) {
} }
func TestRebootDiscoveryListener(t *testing.T) { func TestRebootDiscoveryListener(t *testing.T) {
port := 1024
ipAddr, pkey := createAddrAndPrivKey(t) ipAddr, pkey := createAddrAndPrivKey(t)
db := testDB.SetupDB(t) db := testDB.SetupDB(t)
@@ -376,7 +373,7 @@ func TestRebootDiscoveryListener(t *testing.T) {
ctx: t.Context(), ctx: t.Context(),
genesisTime: time.Now(), genesisTime: time.Now(),
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32), genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),
cfg: &Config{UDPPort: uint(port), DB: db}, cfg: &Config{UDPPort: 0, DB: db}, // Use port 0 to let OS assign an available port
custodyInfo: &custodyInfo{}, custodyInfo: &custodyInfo{},
custodyInfoSet: custodyInfoSet, custodyInfoSet: custodyInfoSet,
} }
@@ -436,9 +433,9 @@ func TestMultiAddrConversion_OK(t *testing.T) {
s := &Service{ s := &Service{
ctx: t.Context(), ctx: t.Context(),
cfg: &Config{ cfg: &Config{
UDPPort: 2000, UDPPort: 0, // Use port 0 to let OS assign an available port
TCPPort: 3000, TCPPort: 0,
QUICPort: 3000, QUICPort: 0,
DB: db, DB: db,
}, },
genesisTime: time.Now(), genesisTime: time.Now(),
@@ -589,7 +586,6 @@ func TestOutboundPeerThreshold(t *testing.T) {
} }
func TestUDPMultiAddress(t *testing.T) { func TestUDPMultiAddress(t *testing.T) {
port := 6500
ipAddr, pkey := createAddrAndPrivKey(t) ipAddr, pkey := createAddrAndPrivKey(t)
genesisTime := time.Now() genesisTime := time.Now()
genesisValidatorsRoot := make([]byte, 32) genesisValidatorsRoot := make([]byte, 32)
@@ -600,7 +596,7 @@ func TestUDPMultiAddress(t *testing.T) {
s := &Service{ s := &Service{
ctx: t.Context(), ctx: t.Context(),
cfg: &Config{UDPPort: uint(port), DB: db}, cfg: &Config{UDPPort: 0, DB: db}, // Use port 0 to let OS assign an available port
genesisTime: genesisTime, genesisTime: genesisTime,
genesisValidatorsRoot: genesisValidatorsRoot, genesisValidatorsRoot: genesisValidatorsRoot,
custodyInfo: &custodyInfo{}, custodyInfo: &custodyInfo{},
@@ -618,7 +614,6 @@ func TestUDPMultiAddress(t *testing.T) {
multiAddresses, err := s.DiscoveryAddresses() multiAddresses, err := s.DiscoveryAddresses()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, true, len(multiAddresses) > 0) require.Equal(t, true, len(multiAddresses) > 0)
assert.Equal(t, true, strings.Contains(multiAddresses[0].String(), fmt.Sprintf("%d", port)))
assert.Equal(t, true, strings.Contains(multiAddresses[0].String(), "udp")) assert.Equal(t, true, strings.Contains(multiAddresses[0].String(), "udp"))
} }
@@ -968,7 +963,7 @@ func TestRefreshPersistentSubnets(t *testing.T) {
actualPingCount++ actualPingCount++
return nil return nil
}, },
cfg: &Config{UDPPort: 2000, DB: testDB.SetupDB(t)}, cfg: &Config{UDPPort: 0, DB: testDB.SetupDB(t)}, // Use port 0 to let OS assign an available port
peers: p2p.Peers(), peers: p2p.Peers(),
genesisTime: time.Now().Add(-time.Duration(tc.epochSinceGenesis*secondsPerEpoch) * time.Second), genesisTime: time.Now().Add(-time.Duration(tc.epochSinceGenesis*secondsPerEpoch) * time.Second),
genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32), genesisValidatorsRoot: bytesutil.PadTo([]byte{'A'}, 32),