| 94 | } |
| 95 | |
| 96 | func TestHTTPProvider_Timeout(t *testing.T) { |
| 97 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 98 | select { |
| 99 | case <-time.After(10 * time.Second): |
| 100 | case <-r.Context().Done(): |
| 101 | } |
| 102 | })) |
| 103 | defer srv.Close() |
| 104 | |
| 105 | p, _ := newTestHTTPProvider(t, srv.URL+"/config.yaml", &http.Client{Timeout: 50 * time.Millisecond}) |
| 106 | |
| 107 | _, err := p.Read(context.Background()) |
| 108 | require.Error(t, err) |
| 109 | |
| 110 | assert.Equal(t, 1, testutil.CollectAndCount(p.requestDuration)) |
| 111 | } |
| 112 | |
| 113 | func TestHTTPProvider_ContextCanceled(t *testing.T) { |
| 114 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |