package api // P5c owner review: regression tests for /v1/extract. import ( "net/http" "testing" "time" ) // Uploads are buffered whole (up to 100 MiB) before the PDF pool sees them, so the number read // at once is bounded: a third concurrent upload waits, then is refused busy. func TestExtractUploadsBounded(t *testing.T) { r := newPDFRig(t) for i := 0; i < cap(r.s.uploads); i++ { r.s.uploads <- struct{}{} } start := time.Now() code, out := r.extract(t, r.fleet, "", threePDF(), "application/pdf") if code != http.StatusTooManyRequests { t.Fatalf("upload with every slot taken: %d %v, want 429", code, out) } if d := time.Since(start); d < uploadWait-100*time.Millisecond { t.Fatalf("refused after %v, want a wait of about %v first", d, uploadWait) } <-r.s.uploads if code, out := r.extract(t, r.fleet, "", threePDF(), "application/pdf"); code != 200 { t.Fatalf("upload with a free slot: %d %v", code, out) } } // The envelope's warnings are a list, never null, as in /v1/fetch. func TestExtractWarningsIsAList(t *testing.T) { r := newPDFRig(t) code, out := r.extract(t, r.fleet, "", threePDF(), "application/pdf") if code != 200 { t.Fatalf("%d %v", code, out) } if _, ok := out["warnings"].([]any); !ok { t.Fatalf("warnings = %#v, want a list", out["warnings"]) } }