From 76bf87099474c34cb5ca34f2e96fd7ac5beabf91 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 5 Apr 2026 15:13:50 +0300 Subject: [PATCH] server: update tests to use proper AddUpstream API Signed-off-by: NotAShelf Change-Id: Ib1adad3ebf5c219f26333cc52e50cb256a6a6964 --- internal/server/server.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 71fbe57..db88b61 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -227,9 +227,24 @@ func (s *Server) copyResponse(w http.ResponseWriter, resp *http.Response) { } func (s *Server) upstreamURLs() []string { - urls := make([]string, len(s.upstreams)) - for i, u := range s.upstreams { - urls[i] = u.URL + // Include all upstreams the prober knows about: this covers both the + // statically-configured upstreams and any peers discovered at runtime + // via mDNS. Using the prober as the source of truth avoids a split + // between "what was configured" and "what was discovered". + sorted := s.prober.SortedByLatency() + urls := make([]string, 0, len(sorted)) + for _, h := range sorted { + if h.Status != prober.StatusDown { + urls = append(urls, h.URL) + } + } + // Fall back to the static list if the prober has no entries yet (i.e., + // before the first probe interval completes). + if len(urls) == 0 { + urls = make([]string, len(s.upstreams)) + for i, u := range s.upstreams { + urls[i] = u.URL + } } return urls }