MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestHandleProxyOriginFetchMetrics

Function TestHandleProxyOriginFetchMetrics

cmd/cache-proxy/proxy_test.go:287–319  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

285 }
286}
287
288func TestHandleProxyRetriesOrigin503ThenCachesSuccess(t *testing.T) {
289 proxy := newTestProxy(t)
290
291 var calls int32
292 _, originURL := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
293 n := atomic.AddInt32(&calls, 1)
294 if n == 1 {
295 w.Header().Set("Content-Type", "application/xml")
296 w.Header().Set("X-Amz-Request-Id", "retry-me")
297 w.WriteHeader(http.StatusServiceUnavailable)
298 _, _ = w.Write([]byte(`<Error><Code>SlowDown</Code></Error>`))
299 return
300 }
301 w.Header().Set("Content-Type", "application/octet-stream")
302 w.WriteHeader(http.StatusOK)
303 _, _ = w.Write([]byte("ok-after-retry"))
304 })
305
306 rec := doForwardProxyRequest(proxy, "GET", originURL+"/bucket/flaky-503.parquet", http.Header{"Range": []string{"bytes=0-13"}})
307 if rec.Code != http.StatusPartialContent {
308 t.Fatalf("status = %d, want 206 after retry", rec.Code)
309 }
310 if got := rec.Body.String(); got != "ok-after-retry" {
311 t.Fatalf("body = %q, want successful retry body", got)
312 }
313 if atomic.LoadInt32(&calls) != 2 {
314 t.Fatalf("origin calls = %d, want 2 (initial 503 + retry success)", calls)
315 }
316
317 rec = doForwardProxyRequest(proxy, "GET", originURL+"/bucket/flaky-503.parquet", http.Header{"Range": []string{"bytes=0-13"}})
318 if rec.Code != http.StatusPartialContent {
319 t.Fatalf("cache hit status = %d, want 206", rec.Code)
320 }
321 if got := rec.Body.String(); got != "ok-after-retry" {
322 t.Fatalf("cache hit body = %q, want successful retry body", got)

Callers

nothing calls this directly

Calls 6

newTestProxyFunction · 0.85
counterValueFunction · 0.85
gaugeValueFunction · 0.85
newTestServerFunction · 0.85
doForwardProxyRequestFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected