oficina / base Public

Keep the upload relay's webtests inside the package's time budget

Human

Prompt

Hub CI on f019e7d: internal/webtest took 13.5s, over the 10s budget.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Shorter waits in the busy, slot-order, stalled and streaming tests, and the over-10-MiB-by-length check moved into the stalled-body test, which already pays Go's half-second wait for a body the server never reads. Same assertions; about 0.9 s off locally (8.7 s against main's 6.9 s).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 16200c8f6d60632a1cc7d0ade4de252d1d43cde3 parent f019e7d
1 file changed, +24 −16
  • internal/webtest/ask_files_test.go +24 −16

CI passed — run details

CI log
=== build ===
CGO_ENABLED=0 go build ./...
=== vet ===
go vet ./...
=== fmt-check ===
=== staticcheck ===
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
=== govulncheck ===
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
No vulnerabilities found.
=== gitleaks ===
4:27PM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
4:27PM INF 1 commits scanned.
4:27PM INF scanned ~2712311 bytes (2.71 MB) in 266ms
4:27PM INF no leaks found
=== budget ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 22 directories within budget
=== script-test ===
scripts/prepare-apps_test.sh
ok   releases lookup failure stops before ship
ok   app owned elsewhere stops the script
ok   apps listing failure stops before create
ok   ambiguous release dir is refused
ok   explicit version resolves the ambiguity
ok   releases match is exact, not substring
ok   shipped version is only promoted, existing app not created
ok   fresh account creates, ships, promotes to edge, enables
ok   failing promote stops the script
ok   ship is retried while uploads are rate limited
all passed
hack/fonts_test.sh
fonts_test: ok
=== test ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./...

receipt: test step 8.985s against a 60s target (the gate's other steps are not in this figure)
receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed
receipt: slow package 8.198s amadan.net/oficina/base/internal/webtest
receipt: slow package 1.106s amadan.net/oficina/base/internal/issuer
receipt: slow package 627ms amadan.net/oficina/base/internal/equipo
receipt: slow package 586ms amadan.net/oficina/base/internal/operations
receipt: slow package 177ms amadan.net/oficina/base/internal/consumer
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.08s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 810ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 620ms amadan.net/oficina/base/internal/webtest TestAskUploadStalledBodyFreesItsSlot
receipt: slow test 520ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
=== native ===
strings: copy review's strings.json is not here (git-ignored); its comparison skipped
strings: 120 in the catalog, 117 used
worktree-lib_test: ok
diff --git a/internal/webtest/ask_files_test.go b/internal/webtest/ask_files_test.go
index 11deba5..e70a618 100644
--- a/internal/webtest/ask_files_test.go
+++ b/internal/webtest/ask_files_test.go
@@ -105,18 +105,14 @@ func TestAskUploadRelays(t *testing.T) {
a.noLeak(token)
}
-// Over 10 MiB is refused before Equipo hears of it, whether the length
-// is declared or not.
+// A body of unknown length is refused before Equipo hears of it (Fable
+// N1): a browser always says a File's length. (A declared length over
+// 10 MiB is in TestAskUploadStalledBodyFreesItsSlot, which already pays
+// for a body the server never reads.)
func TestAskUploadTooBig(t *testing.T) {
a, f := newAskApp(t)
a.connectEquipo(f)
- big := bytes.Repeat([]byte("a"), 10<<20+1)
- if r := a.upload("big.txt", "text/plain", big); r.Code != 413 {
- t.Fatalf("declared: %d %s", r.Code, r.Body)
- }
- // A body of unknown length is refused before it is read (Fable N1): a
- // browser always says a File's length.
- req := a.uploadReq(context.Background(), "big.txt", "text/plain", io.MultiReader(bytes.NewReader(big)))
+ req := a.uploadReq(context.Background(), "big.txt", "text/plain", io.MultiReader(strings.NewReader("a few bytes")))
req.ContentLength = -1
r := a.do(req)
if code, _, _ := codeOf(r); r.Code != 411 || code != "length_required" {
@@ -239,9 +235,10 @@ func (a *testApp) uploadAll(n int) []int {
}
// A body that stalls loses its slot at the read deadline, through the
-// whole router (Fable B3): afterwards four uploads at once all pass.
+// whole router (Fable B3): afterwards four uploads at once all pass. A
+// declared length over 10 MiB is refused from the headers alone.
func TestAskUploadStalledBodyFreesItsSlot(t *testing.T) {
- bounds(t, web.UploadBounds{Slots: 4, SlotWait: 60 * time.Millisecond, ReadDeadline: 150 * time.Millisecond, Upstream: 5 * time.Second})
+ bounds(t, web.UploadBounds{Slots: 4, SlotWait: 40 * time.Millisecond, ReadDeadline: 100 * time.Millisecond, Upstream: 5 * time.Second})
a, f := newAskApp(t)
a.connectEquipo(f)
u, _ := url.Parse(a.base)
@@ -259,7 +256,18 @@ func TestAskUploadStalledBodyFreesItsSlot(t *testing.T) {
if took := time.Since(start); took > 3*time.Second || err == nil && res.StatusCode != 400 {
t.Fatalf("the stalled upload held on for %s (%v %v)", took, res, err)
}
- f.SlowUploads(120 * time.Millisecond)
+ big, err := net.Dial("tcp", u.Host)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer big.Close()
+ fmt.Fprintf(big, "POST /ask/attachments HTTP/1.1\r\nHost: %s\r\nOrigin: %s\r\nAccept: application/json\r\nCookie: %s\r\n"+
+ "Content-Type: text/plain\r\nContent-Length: %d\r\n\r\n", u.Host, a.origin, a.cookieHeader(), 10<<20+1)
+ _ = big.SetReadDeadline(time.Now().Add(5 * time.Second))
+ if res, err := http.ReadResponse(bufio.NewReader(big), nil); err != nil || res.StatusCode != 413 {
+ t.Fatalf("declared over 10 MiB: %v %v", res, err)
+ }
+ f.SlowUploads(80 * time.Millisecond)
for i, code := range a.uploadAll(4) {
if code != 201 {
t.Fatalf("upload %d after the stall: %d", i, code)
@@ -269,10 +277,10 @@ func TestAskUploadStalledBodyFreesItsSlot(t *testing.T) {
// Every slot busy: a fifth upload waits, then is told to come back.
func TestAskUploadBusy(t *testing.T) {
- bounds(t, web.UploadBounds{Slots: 4, SlotWait: 100 * time.Millisecond, ReadDeadline: 5 * time.Second, Upstream: 10 * time.Second})
+ bounds(t, web.UploadBounds{Slots: 4, SlotWait: 60 * time.Millisecond, ReadDeadline: 5 * time.Second, Upstream: 10 * time.Second})
a, f := newAskApp(t)
a.connectEquipo(f)
- f.SlowUploads(500 * time.Millisecond)
+ f.SlowUploads(300 * time.Millisecond)
done := make(chan []int)
go func() { done <- a.uploadAll(4) }()
for i := 0; f.UploadsAtOnce() < 4; i++ {
@@ -302,7 +310,7 @@ func TestAskUploadSlotComesFirst(t *testing.T) {
t.Cleanup(func() { web.UploadReading = nil })
a, f := newAskApp(t)
a.connectEquipo(f)
- f.SlowUploads(150 * time.Millisecond)
+ f.SlowUploads(80 * time.Millisecond)
for i, code := range a.uploadAll(8) {
if code != 201 {
t.Fatalf("upload %d: %d", i, code)
@@ -465,7 +473,7 @@ func TestAskAttachmentStreams(t *testing.T) {
a.connectEquipo(f)
big := bytes.Repeat([]byte("0123456789abcdef"), 9<<20/16)
id := uploaded(t, a.upload("big.txt", "text/plain", big))
- f.ServeSlowly(1500 * time.Microsecond) // 144 pieces: about 0.2 s
+ f.ServeSlowly(700 * time.Microsecond) // 144 pieces: about 0.1 s
start := time.Now()
res, err := a.client.Get(a.base + "/ask/attachments/" + id)
if err != nil {