mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-23 00:56:20 +00:00
net/udprelay: replace VNI pool with selection algorithm (#17868)
This reduces memory usage when tailscaled is acting as a peer relay. Updates #17801 Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"go4.org/mem"
|
||||
@@ -319,3 +320,25 @@ func TestServer(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_getNextVNILocked(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
s := &Server{
|
||||
nextVNI: minVNI,
|
||||
byVNI: make(map[uint32]*serverEndpoint),
|
||||
}
|
||||
for i := uint64(0); i < uint64(totalPossibleVNI); i++ {
|
||||
vni, err := s.getNextVNILocked()
|
||||
if err != nil { // using quicktest here triples test time
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.byVNI[vni] = nil
|
||||
}
|
||||
c.Assert(s.nextVNI, qt.Equals, minVNI)
|
||||
_, err := s.getNextVNILocked()
|
||||
c.Assert(err, qt.IsNotNil)
|
||||
delete(s.byVNI, minVNI)
|
||||
_, err = s.getNextVNILocked()
|
||||
c.Assert(err, qt.IsNil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user