From b8edfcec370516b671f2c5214c09c843a08fad28 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 4 Oct 2026 08:19:19 +0000 Subject: [PATCH] Spend less of make test writing the image and waiting (closes #56) The test phase spends most of its time compiling with the race detector from an empty build cache; then come writing the test image and the internal/proxy tests. - Go's build cache is on a tmpfs in the test phase, so its 137 MB are no longer written into the test image. - TestUpgradedConnectionOutlastsTheTimeouts waits until just past shortTimeout after the request was sent, rather than 7.5 s after the upgrade, so it ends with the other timing tests. - shortTimeout is written as waitLimit / 2, as its comment says it is. Model: opus-5-5 --- Dockerfile | 5 ++++- internal/proxy/passthrough_test.go | 8 +++++--- internal/proxy/proxy_test.go | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30aace9..79d3ef4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,10 @@ RUN go mod download COPY . . -RUN go test -count=1 -timeout 90s -race -cover ./... || \ +# Go's build cache is kept on a tmpfs, out of the image: nothing uses it +# after this step, and writing it into the image takes seconds. +RUN --mount=type=tmpfs,target=/root/.cache/go-build \ + go test -count=1 -timeout 90s -race -cover ./... || \ { echo "--- Rerunning with -v for details ---"; \ go test -count=1 -timeout 90s -race -v ./...; exit 1; } diff --git a/internal/proxy/passthrough_test.go b/internal/proxy/passthrough_test.go index 8f644bb..4048fce 100644 --- a/internal/proxy/passthrough_test.go +++ b/internal/proxy/passthrough_test.go @@ -233,6 +233,7 @@ func TestUpgradedConnectionOutlastsTheTimeouts(t *testing.T) { send(t, conn, "GET /socket HTTP/1.1\r\nHost: app\r\n"+ "Connection: Upgrade\r\nUpgrade: websocket\r\n\r\n") + sent := time.Now() reader := bufio.NewReader(conn) res, err := http.ReadResponse(reader, nil) @@ -246,9 +247,10 @@ func TestUpgradedConnectionOutlastsTheTimeouts(t *testing.T) { t.Fatalf("status %d, want %d", res.StatusCode, http.StatusSwitchingProtocols) } - // Every timeout started before the upgrade was answered: wait past - // them all, then use the connection. - time.Sleep(3 * shortTimeout / 2) + // Every timeout started by the time smallwebwaf read the request: + // wait until just past shortTimeout after it was sent, then use the + // connection. + time.Sleep(time.Until(sent.Add(shortTimeout + 100*time.Millisecond))) send(t, conn, "still here\n") echoed, err := reader.ReadString('\n') diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 0e7dea7..24b33f4 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -23,9 +23,9 @@ const ( // shortTimeout is what a test sets a timeout to, to see it run out. // It starts before the test has set up its case, such as an upgrade // or the app's buffers filling, so it is as long as the hold-up of the - // test process that wantTimedOut allows, waitLimit/2: a shorter one - // can run out first on a busy host. - shortTimeout = 5 * time.Second + // test process that wantTimedOut allows: a shorter one can run out + // first on a busy host. + shortTimeout = waitLimit / 2 // shortTimeoutSetting is shortTimeout as a setting's value. shortTimeoutSetting = "5s" // longTimeoutSetting is a timeout that does not run out in a test.