MCPcopy
hub / github.com/cortesi/devd / TestReverseProxyFlushInterval

Function TestReverseProxyFlushInterval

reverseproxy/reverseproxy_test.go:166–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func 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}

Callers

nothing calls this directly

Calls 3

WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected