Skip to content

Commit 2e0d2c3

Browse files
committed
fix(test): use unique local addresses
1 parent bcfab9b commit 2e0d2c3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

sei-tendermint/internal/p2p/conn_tracker_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ func randLocalAddr() netip.AddrPort {
2525
)
2626
}
2727

28+
// uniqueLocalAddr generates a unique IP address based on the index.
29+
// This is used in tests that require guaranteed unique IPs to avoid flakiness.
30+
func uniqueLocalAddr(i int) netip.AddrPort {
31+
return netip.AddrPortFrom(
32+
netip.AddrFrom4([4]byte{127, byte(i / 65536), byte((i / 256) % 256), byte(i % 256)}),
33+
uint16(i),
34+
)
35+
}
36+
2837
func TestConnTracker(t *testing.T) {
2938
for name, factory := range map[string]func() *connTracker{
3039
"BaseSmall": func() *connTracker {
@@ -59,7 +68,7 @@ func TestConnTracker(t *testing.T) {
5968
t.Run("Cycle", func(t *testing.T) {
6069
ct := factory()
6170
for i := 0; i < 100; i++ {
62-
ip := randLocalAddr()
71+
ip := uniqueLocalAddr(i)
6372
require.NoError(t, ct.AddConn(ip))
6473
ct.RemoveConn(ip)
6574
}

0 commit comments

Comments
 (0)