[arvados] updated: 2.5.0-288-gc16b905d8

git repository hosting git at public.arvados.org
Wed Mar 15 18:39:15 UTC 2023


Summary of changes:
 lib/controller/handler.go      | 12 ++++++++++--
 lib/controller/handler_test.go | 26 +++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)

       via  c16b905d89fb7c2b9ed8f91ca299f08874b58dab (commit)
       via  b8d80c01a51ce3d271f838231b90e70bf4460d0e (commit)
      from  dae3da4d70bfba901f2147775dd6c07be61416b2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit c16b905d89fb7c2b9ed8f91ca299f08874b58dab
Author: Tom Clegg <tom at curii.com>
Date:   Wed Mar 15 14:38:53 2023 -0400

    20187: Fix test race.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go
index 02b72dc45..654eaffe1 100644
--- a/lib/controller/handler_test.go
+++ b/lib/controller/handler_test.go
@@ -256,6 +256,7 @@ func (s *HandlerSuite) TestDiscoveryDocCache(c *check.C) {
 	holdReqs = make(chan struct{})
 	getDDConcurrently(5, http.StatusOK, check.Commentf("refresh cache after error condition clears")).Wait()
 	close(holdReqs)
+	waitPendingUpdates()
 	c.Check(countRailsReqs(), check.Equals, reqsBefore+1)
 }
 

commit b8d80c01a51ce3d271f838231b90e70bf4460d0e
Author: Tom Clegg <tom at curii.com>
Date:   Wed Mar 15 14:28:16 2023 -0400

    20187: Check that the discovery doc is really a discovery doc.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/controller/handler.go b/lib/controller/handler.go
index b3d850ac0..c213c897c 100644
--- a/lib/controller/handler.go
+++ b/lib/controller/handler.go
@@ -171,7 +171,7 @@ func (h *Handler) setup() {
 		Name: "arvados-controller",
 	}
 	h.cache = map[string]*cacheEnt{
-		"/discovery/v1/apis/arvados/v1/rest": &cacheEnt{},
+		"/discovery/v1/apis/arvados/v1/rest": &cacheEnt{validateDD: true},
 	}
 
 	go h.trashSweepWorker()
@@ -222,6 +222,7 @@ func (h *Handler) limitLogCreateRequests(w http.ResponseWriter, req *http.Reques
 // cacheEnt implements a basic stale-while-revalidate cache, suitable
 // for the Arvados discovery document.
 type cacheEnt struct {
+	validateDD   bool
 	mtx          sync.Mutex
 	header       http.Header
 	body         []byte
@@ -277,7 +278,14 @@ func (ent *cacheEnt) refresh(path string, do func(*http.Request) (*http.Response
 			header[k] = v
 		}
 	}
-	if mediatype, _, err := mime.ParseMediaType(header.Get("Content-Type")); err == nil && mediatype == "application/json" {
+	if ent.validateDD {
+		var dd arvados.DiscoveryDocument
+		if err := json.Unmarshal(body, &dd); err != nil {
+			return nil, nil, fmt.Errorf("error decoding JSON response: %w", err)
+		} else if dd.BasePath == "" {
+			return nil, nil, errors.New("error in discovery document: no value for basePath")
+		}
+	} else if mediatype, _, err := mime.ParseMediaType(header.Get("Content-Type")); err == nil && mediatype == "application/json" {
 		if !json.Valid(body) {
 			return nil, nil, errors.New("invalid JSON encoding in response")
 		}
diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go
index 4a7e1ad78..02b72dc45 100644
--- a/lib/controller/handler_test.go
+++ b/lib/controller/handler_test.go
@@ -131,8 +131,12 @@ func (s *HandlerSuite) TestDiscoveryDocCache(c *check.C) {
 		return &wg
 	}
 	clearCache := func() {
-		for path := range s.handler.cache {
-			s.handler.cache[path] = &cacheEnt{}
+		for _, ent := range s.handler.cache {
+			ent.refreshLock.Lock()
+			ent.mtx.Lock()
+			ent.body, ent.header, ent.refreshAfter = nil, nil, time.Time{}
+			ent.mtx.Unlock()
+			ent.refreshLock.Unlock()
 		}
 	}
 	expireCache := func() {
@@ -188,11 +192,15 @@ func (s *HandlerSuite) TestDiscoveryDocCache(c *check.C) {
 	}
 	c.Check(countRailsReqs(), check.Equals, reqsBefore+1)
 
-	// Configure railsSpy to return an error when wantError==true.
-	var wantError bool
+	// Configure railsSpy to return an error or bad content
+	// depending on flags.
+	var wantError, wantBadContent bool
 	s.railsSpy.Director = func(req *http.Request) {
 		if wantError {
 			req.Method = "MAKE-COFFEE"
+		} else if wantBadContent {
+			req.URL.Path = "/_health/ping"
+			req.Header.Set("Authorization", "Bearer "+arvadostest.ManagementToken)
 		}
 	}
 
@@ -208,9 +216,16 @@ func (s *HandlerSuite) TestDiscoveryDocCache(c *check.C) {
 	wg.Wait()
 	c.Check(countRailsReqs(), check.Equals, reqsBefore+5)
 
+	// Response status is OK but body is not a discovery document
+	wantError = false
+	wantBadContent = true
+	reqsBefore = countRailsReqs()
+	c.Check(getDD(), check.Equals, http.StatusBadGateway)
+	c.Check(countRailsReqs(), check.Equals, reqsBefore+1)
+
 	// Error condition clears => caller gets OK, cache is warmed
 	// up
-	wantError = false
+	wantBadContent = false
 	reqsBefore = countRailsReqs()
 	getDDConcurrently(5, http.StatusOK, check.Commentf("success after errors at startup")).Wait()
 	c.Check(countRailsReqs(), check.Equals, reqsBefore+1)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list