mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
outlet/rib: don't create collisions during tests
I don't know why this was done. I suppose there was a test around that, but we don't have it anymore. This made the benchmark tests "bad".
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2022 Free Mobile
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
//go:build release
|
||||
|
||||
package bmp
|
||||
|
||||
const rtaHashMask = 0xffffffffffffffff
|
||||
@@ -109,7 +109,7 @@ func (rta routeAttributes) Hash() uint64 {
|
||||
// 16-byte).
|
||||
state.Add((*byte)(unsafe.Pointer(&rta.largeCommunities[0])), len(rta.largeCommunities)*int(unsafe.Sizeof(rta.largeCommunities[0])))
|
||||
}
|
||||
return state.Sum() & rtaHashMask
|
||||
return state.Sum()
|
||||
}
|
||||
|
||||
// Equal tells if two route attributes are equal.
|
||||
|
||||
@@ -5,7 +5,6 @@ package bmp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/maphash"
|
||||
"math/rand"
|
||||
"net/netip"
|
||||
"testing"
|
||||
@@ -166,29 +165,19 @@ func TestRTAEqual(t *testing.T) {
|
||||
false,
|
||||
},
|
||||
}
|
||||
outer:
|
||||
for try := 3; try >= 0; try-- {
|
||||
// We may have to try a few times because of
|
||||
// collisions due to reduced hash efficiency during
|
||||
// tests.
|
||||
for _, tc := range cases {
|
||||
equal := tc.rta1.Equal(tc.rta2)
|
||||
|
||||
for _, tc := range cases {
|
||||
equal := tc.rta1.Equal(tc.rta2)
|
||||
if equal && !tc.equal {
|
||||
t.Errorf("%s%+v == %+v", tc.pos, tc.rta1, tc.rta2)
|
||||
} else if !equal && tc.equal {
|
||||
t.Errorf("%s%+v != %+v", tc.pos, tc.rta1, tc.rta2)
|
||||
} else {
|
||||
equal := tc.rta1.Hash() == tc.rta2.Hash()
|
||||
if equal && !tc.equal {
|
||||
t.Errorf("%s%+v == %+v", tc.pos, tc.rta1, tc.rta2)
|
||||
t.Errorf("%s%+v.hash == %+v.hash", tc.pos, tc.rta1, tc.rta2)
|
||||
} else if !equal && tc.equal {
|
||||
t.Errorf("%s%+v != %+v", tc.pos, tc.rta1, tc.rta2)
|
||||
} else {
|
||||
equal := tc.rta1.Hash() == tc.rta2.Hash()
|
||||
if equal && !tc.equal {
|
||||
if try > 0 {
|
||||
// We may have a collision, change the seed and retry
|
||||
rtaHashSeed = maphash.MakeSeed()
|
||||
continue outer
|
||||
}
|
||||
t.Errorf("%s%+v.hash == %+v.hash", tc.pos, tc.rta1, tc.rta2)
|
||||
} else if !equal && tc.equal {
|
||||
t.Errorf("%s%+v.hash != %+v.hash", tc.pos, tc.rta1, tc.rta2)
|
||||
}
|
||||
t.Errorf("%s%+v.hash != %+v.hash", tc.pos, tc.rta1, tc.rta2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,10 +139,6 @@ func (p *Provider) LocalAddr() net.Addr {
|
||||
return p.address
|
||||
}
|
||||
|
||||
// Reduce hash mask to generate collisions during tests (this should
|
||||
// be optimized out by the compiler)
|
||||
const rtaHashMask = 0xff
|
||||
|
||||
// MustParseRD parse a route distinguisher and panic on error.
|
||||
func MustParseRD(input string) RD {
|
||||
var output RD
|
||||
|
||||
Reference in New Issue
Block a user