(t *testing.T)
| 164 | } |
| 165 | |
| 166 | func TestReverseProxyFlushInterval(t *testing.T) { |
| 167 | const expected = "hi" |
| 168 | backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 169 | w.Write([]byte(expected)) |
| 170 | })) |
| 171 | defer backend.Close() |
| 172 | |
| 173 | backendURL, err := url.Parse(backend.URL) |
| 174 | if err != nil { |
| 175 | t.Fatal(err) |
| 176 | } |
| 177 | |
| 178 | proxyHandler := NewSingleHostReverseProxy(backendURL, inject.CopyInject{}) |
| 179 | proxyHandler.FlushInterval = time.Microsecond |
| 180 | |
| 181 | done := make(chan bool) |
| 182 | onExitFlushLoop = func() { done <- true } |
| 183 | defer func() { onExitFlushLoop = nil }() |
| 184 | |
| 185 | frontend := httptest.NewServer(proxyHandler) |
| 186 | defer frontend.Close() |
| 187 | |
| 188 | req, _ := http.NewRequest("GET", frontend.URL, nil) |
| 189 | req.Close = true |
| 190 | res, err := http.DefaultClient.Do(req) |
| 191 | if err != nil { |
| 192 | t.Fatalf("Get: %v", err) |
| 193 | } |
| 194 | defer res.Body.Close() |
| 195 | if bodyBytes, _ := ioutil.ReadAll(res.Body); string(bodyBytes) != expected { |
| 196 | t.Errorf("got body %q; expected %q", bodyBytes, expected) |
| 197 | } |
| 198 | |
| 199 | select { |
| 200 | case <-done: |
| 201 | // OK |
| 202 | case <-time.After(5 * time.Second): |
| 203 | t.Error("maxLatencyWriter flushLoop() never exited") |
| 204 | } |
| 205 | } |
nothing calls this directly
no test coverage detected