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

Function TestHandlePeerHasAndGet

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

Source from the content-addressed store, hash-verified

757 if rec.Code != http.StatusNotFound {
758 t.Fatalf("status = %d, want 404 forwarded verbatim", rec.Code)
759 }
760}
761
762// TestHandleProxyForwardsOrigin416Verbatim: Range Not Satisfiable carries
763// semantically important metadata for DuckLake; collapsing to 502 made it
764// look like a network error.
765func TestHandleProxyForwardsOrigin416Verbatim(t *testing.T) {
766 proxy := newTestProxy(t)
767 _, originURL := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
768 w.Header().Set("Content-Range", "bytes */1024")
769 w.WriteHeader(http.StatusRequestedRangeNotSatisfiable)
770 })
771 rec := doForwardProxyRequest(proxy, "GET", originURL+"/bucket/short.parquet", http.Header{"Range": []string{"bytes=999999-1000000"}})
772 if rec.Code != http.StatusRequestedRangeNotSatisfiable {
773 t.Fatalf("status = %d, want 416 forwarded verbatim", rec.Code)
774 }
775 if cr := rec.Header().Get("Content-Range"); cr != "bytes */1024" {
776 t.Errorf("Content-Range = %q, want 'bytes */1024' (DuckDB uses this to learn the actual file size)", cr)
777 }
778}
779
780// TestHandleProxyDoesNotCacheErrorResponses: a transient origin error
781// must not poison the cache. The next request for the same key has to hit
782// the origin again — otherwise an ExpiredToken error would persist past
783// the credential refresh that fixes it.
784func TestHandleProxyDoesNotCacheErrorResponses(t *testing.T) {
785 proxy := newTestProxy(t)
786 var calls int32
787 _, originURL := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
788 n := atomic.AddInt32(&calls, 1)
789 if n == 1 {
790 w.WriteHeader(http.StatusBadRequest)
791 _, _ = w.Write([]byte("first call fails"))
792 return
793 }
794 w.Header().Set("Content-Type", "application/octet-stream")
795 w.WriteHeader(http.StatusOK)
796 _, _ = w.Write([]byte("ok-now"))
797 })
798

Callers

nothing calls this directly

Calls 5

newTestProxyFunction · 0.85
PutMethod · 0.80
HandlePeerHasMethod · 0.80
HandlePeerGetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected