internal/gateway hit go test's default 10m timeout under a full ./... on
a loaded Mac. go test -json timed its 1583 top-level tests at ~306s
summed (they run one after another); the slowest few waited on real
clocks for things the tests don't check.
- TestQueuedStreamFailureIsTheStreamsError (27s -> 0.3s): it queued for
room in a 3s minute (MaxRPM 1), and each of the vendor's two retries
waited a minute more, 9s a protocol. It now queues for a slot
(MaxConcurrency 1, freed once the agent has heard a keepalive), which
goes through the same keepQueued, queuedAlive and watch around the
attempt, so its retries go at once. The assertions are unchanged.
- TestQueuedStreamKeptAliveOnceSentToItsVendor (15s -> 7.6s): the same
slot instead of a 4s minute; keepHeldAfter 1.5s, keepalive 100ms and
the vendor's 1s quiet stay. With the h.alive.sent clause in
holdWriter.watch removed by hand it goes red on all three protocols
("wrote nothing ... between the vendor being asked and its answer").
- TestQueuedStreamKeptAliveForTheMinute keeps the MaxRPM queue.
- A shared holdSlot helper holds the slot; it frees itself after 5s and
in cleanup, so a test that hears nothing fails instead of hanging.
- usage.OTelEvery / OTelSessionsEvery (5s / 2s, read once when StartOTel
starts an exporter) replace the hard-coded tickers; the gateway's OTel
tests set them to 200ms / 50ms through fastOTel.
TestOTelClaudeMainAndChildDedupRetainsHelper 10s -> 4.5s (the rest is
sessions' 2s settle before a Claude transcript counts as finished),
TestOTelSessionDedupOnlyUnkeyedLoopback 2.25s -> 0.4s. Production
intervals are unchanged.
Not cut: TestPluginStreamLargeReplies (22s, 24MB throttled at 3MB/s),
TestPluginStreamLongActiveReader (16s, sized to outlast a 10s stall
window the plugin host dropped in c38728145), TestLargeRequestEndpoints
(16s, a 64MB body the gateway parses many times over - product speed,
not test waits), and the many 1-3s tests.
Run: go test -count=3 -run 'TestQueued|TestOTel' ./internal/gateway (ok),
-race -count=2 of the same (ok), go test ./internal/usage (ok);
go test -count=1 -json ./internal/gateway: tests summed 305.9s before,
the changed ones ~41.6s less after; the whole run took 330.6s at load
average ~125 against 306.7s for the baseline, other tests slowing under
that load (e.g. TestWarmClaudeSaysWhyNot 0.26s -> 5.3s). gofmt -l clean;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway
./internal/usage clean.