TestQueryWithRetryFail function statResponseWriter's statusCode will not be 200, but the query has been proxied The request will be retried 1 time with a different host in the same replica
(t *testing.T)
| 36 | // TestQueryWithRetryFail function statResponseWriter's statusCode will not be 200, but the query has been proxied |
| 37 | // The request will be retried 1 time with a different host in the same replica |
| 38 | func TestQueryWithRetryFail(t *testing.T) { |
| 39 | body := "foo query" |
| 40 | |
| 41 | req := newRequest("http://localhost:8080", body) |
| 42 | |
| 43 | mhs := &mockHosts{ |
| 44 | t: t, |
| 45 | b: body, |
| 46 | hs: []string{"localhost:8080", "localhost:8081"}, |
| 47 | } |
| 48 | |
| 49 | s := newMockScope(mhs.hs) |
| 50 | |
| 51 | srw := mockStatRW(s) |
| 52 | |
| 53 | mrw := &mockResponseWriterWithCode{ |
| 54 | statusCode: 0, |
| 55 | } |
| 56 | |
| 57 | retryNum := 1 |
| 58 | |
| 59 | _, err := executeWithRetry( |
| 60 | context.Background(), |
| 61 | s, |
| 62 | retryNum, |
| 63 | mhs.mockReverseProxy, |
| 64 | mrw, |
| 65 | srw, |
| 66 | req, |
| 67 | func(f float64) {}, |
| 68 | func(l prometheus.Labels) {}, |
| 69 | ) |
| 70 | |
| 71 | if err != nil { |
| 72 | t.Errorf("the execution with retry failed: %v", err) |
| 73 | } |
| 74 | assert.Equal(t, srw.statusCode, http.StatusBadGateway) |
| 75 | assert.Equal(t, mhs.hs, mhs.hst) |
| 76 | |
| 77 | } |
| 78 | |
| 79 | // TestRunQuerySuccessOnce function statResponseWriter's statusCode will be StatusOK after executeWithRetry, the query has been proxied |
| 80 | // The execution will succeeded without retry |
nothing calls this directly
no test coverage detected