MCPcopy Create free account
hub / github.com/tailscale/tailcat / TestFetchDERPMapMemoryCache

Function TestFetchDERPMapMemoryCache

tailcat_test.go:428–448  ·  view source on GitHub ↗

TestFetchDERPMapMemoryCache verifies the default in-memory DERP map cache: a second fetch of the same URL within the freshness window makes no network request.

(t *testing.T)

Source from the content-addressed store, hash-verified

426// cache: a second fetch of the same URL within the freshness window
427// makes no network request.
428func TestFetchDERPMapMemoryCache(t *testing.T) {
429 var fetches atomic.Int32
430 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
431 fetches.Add(1)
432 fmt.Fprint(w, `{"Regions":{"1":{"RegionID":1}}}`)
433 }))
434 defer srv.Close()
435
436 for range 2 {
437 dm, err := FetchDERPMap(context.Background(), DERPMapURL(srv.URL))
438 if err != nil {
439 t.Fatal(err)
440 }
441 if len(dm.Regions) != 1 {
442 t.Fatalf("got %d regions; want 1", len(dm.Regions))
443 }
444 }
445 if n := fetches.Load(); n != 1 {
446 t.Errorf("fetches = %d; want 1", n)
447 }
448}

Callers

nothing calls this directly

Calls 3

CloseMethod · 0.95
FetchDERPMapFunction · 0.85
DERPMapURLTypeAlias · 0.85

Tested by

no test coverage detected