TestQueryWithRetrySuccess function statResponseWriter's statusCode will be StatusOK after executeWithRetry, the query has been proxied The execution will succeeded after retry
(t *testing.T)
| 120 | // TestQueryWithRetrySuccess function statResponseWriter's statusCode will be StatusOK after executeWithRetry, the query has been proxied |
| 121 | // The execution will succeeded after retry |
| 122 | func TestQueryWithRetrySuccess(t *testing.T) { |
| 123 | body := "foo query" |
| 124 | |
| 125 | req := newRequest("http://localhost:8080", body) |
| 126 | |
| 127 | mhs := &mockHosts{ |
| 128 | t: t, |
| 129 | b: body, |
| 130 | hs: []string{"localhost:8080", "localhost:8090"}, |
| 131 | } |
| 132 | |
| 133 | s := newMockScope(mhs.hs) |
| 134 | |
| 135 | srw := mockStatRW(s) |
| 136 | |
| 137 | mrw := &mockResponseWriterWithCode{ |
| 138 | statusCode: 0, |
| 139 | } |
| 140 | |
| 141 | retryNum := 1 |
| 142 | |
| 143 | erroredHost := s.host |
| 144 | |
| 145 | _, err := executeWithRetry( |
| 146 | context.Background(), |
| 147 | s, |
| 148 | retryNum, |
| 149 | mhs.mockReverseProxy, |
| 150 | mrw, |
| 151 | srw, |
| 152 | req, |
| 153 | func(f float64) {}, |
| 154 | func(l prometheus.Labels) {}, |
| 155 | ) |
| 156 | if err != nil { |
| 157 | t.Errorf("The execution with retry failed, %v", err) |
| 158 | } |
| 159 | assert.Equal(t, 200, srw.statusCode) |
| 160 | assert.Equal(t, 1, int(s.host.CurrentConnections())) |
| 161 | assert.Equal(t, 0, int(s.host.CurrentPenalty())) |
| 162 | // should be counter + penalty |
| 163 | assert.Equal(t, 1, int(s.host.CurrentLoad())) |
| 164 | |
| 165 | assert.Equal(t, 0, int(erroredHost.CurrentConnections())) |
| 166 | assert.Equal(t, topology.DefaultPenaltySize, int(erroredHost.CurrentPenalty())) |
| 167 | // should be counter + penalty |
| 168 | assert.Equal(t, topology.DefaultPenaltySize, int(erroredHost.CurrentLoad())) |
| 169 | |
| 170 | assert.Equal(t, mhs.hs, mhs.hst) |
| 171 | } |
| 172 | |
| 173 | func (mhs *mockHosts) mockReverseProxy(rw http.ResponseWriter, req *http.Request) { |
| 174 | if req.URL.Host != "localhost:8090" { |
nothing calls this directly
no test coverage detected