From 9f604f2bd3b48fc4464727b7ac6f5ee56d02413c Mon Sep 17 00:00:00 2001 From: Maisem Ali <3953239+maisem@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:50:50 -0700 Subject: [PATCH] derp: add (*Server).IsClientConnectedForTest func. (#4331) This allows tests to verfiy that a DERP connection was actually established. Related to #4326 Updates tailscale/corp#2579 Signed-off-by: Maisem Ali --- derp/derp_server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/derp/derp_server.go b/derp/derp_server.go index 65c3340c6..ec50e53f4 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -391,6 +391,18 @@ func (s *Server) isClosed() bool { return s.closed } +// IsClientConnectedForTest reports whether the client with specified key is connected. +// This is used in tests to verify that nodes are connected. +func (s *Server) IsClientConnectedForTest(k key.NodePublic) bool { + s.mu.Lock() + defer s.mu.Unlock() + x, ok := s.clients[k] + if !ok { + return false + } + return x.ActiveClient() != nil +} + // Accept adds a new connection to the server and serves it. // // The provided bufio ReadWriter must be already connected to nc.