tstest/natlab/vmtest: add test loading netmap cache from disk (#19598)

For testing the loading of netmap cache from disk, the cache needs to
exist. The simple solution is to start two nodes and connect them to
control, with the netmap caching capability set. Then cut the connection
to control, restart the nodes, and ping between them.

This tests that we can start from a cache and get to running state, but
also that we are able to establish a connection between the nodes.

For now this is not testing how the nodes are able to talk to each other
(DERP vs direct).

Updates #19597

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
Claus Lensbøl
2026-05-01 09:46:19 -04:00
committed by GitHub
parent 89a78dc9b7
commit ff9c3f0e00
3 changed files with 117 additions and 0 deletions
@@ -162,6 +162,10 @@ type Server struct {
// tkaStorage records the Tailnet Lock state, if any.
// If nil, Tailnet Lock is not enabled in the Tailnet.
tkaStorage tka.CompactableChonk
// onMapRequest, if non-nil, is called at the start of each map poll request.
// It can be used in tests to panic or fail if a node contacts control unexpectedly.
onMapRequest func(nodeKey key.NodePublic)
}
// BaseURL returns the server's base URL, without trailing slash.
@@ -1169,6 +1173,12 @@ func (s *Server) serveMap(w http.ResponseWriter, r *http.Request, mkey key.Machi
go panic(fmt.Sprintf("bad map request: %v", err))
}
s.mu.Lock()
if s.onMapRequest != nil {
s.onMapRequest(req.NodeKey)
}
s.mu.Unlock()
if s.AltMapStream != nil {
// The caller takes over the stream entirely; it must handle
// keeping the HTTP response alive until ctx is done.
@@ -1620,6 +1630,15 @@ func (s *Server) encode(compress bool, v any) (b []byte, err error) {
return b, nil
}
// SetOnMapRequest sets callback used for testing when a new mapRequest happens.
// Pass nil to remove the callback.
func (s *Server) SetOnMapRequest(f func(key.NodePublic)) {
s.mu.Lock()
defer s.mu.Unlock()
s.onMapRequest = f
}
// filterInvalidIPv6Endpoints removes invalid IPv6 endpoints from eps,
// modify the slice in place, returning the potentially smaller subset (aliasing
// the original memory).