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)
| 426 | // cache: a second fetch of the same URL within the freshness window |
| 427 | // makes no network request. |
| 428 | func 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 | } |
nothing calls this directly
no test coverage detected