Give the daemon tests an API rate limit their polling cannot reach
Security / Vulnerability check (push) Successful in 47s
Test / Lint and test (push) Successful in 4m10s

TestServeRestart failed on CI with a restored job and the seeded job
reading rate_limited. The daemon tests poll GET /api/v1/jobs/{id}
every 20 ms under the default limit of 60 API requests a minute per
client. Once those are spent, every request is refused for the rest of
the minute, and the test's status helper returned the refusal's code as
the job's status. The restored jobs retry with a doubling delay, so the
slower the start, the longer they wait once the fake printer is up: up
to 1.6 s when it comes up 1.5 s after the queue starts, more than the
budget lasts at that rate. TestServeUnconfirmedJobReadsUncertain and
TestServeEndToEnd poll the same way and shared the risk.

The test daemons now allow a million API requests a minute, set in
testConfig and in TestServeEndToEnd's config file. Their job polls fail
the test on any answer that is not the job, so a refusal shows as one.

The limiter is unchanged: it did what it was configured to do. Starting
the second run's fake printer 1.6 s late reproduced the failure here,
on the 61st request, and the test now passes that way after 101 polls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 23:03:14 -06:00
1 parent 188230b579
commit 78a382fbdc
2 files changed
+18 -8

No files matched your search

+4 -6
View File
@@ -97,7 +97,8 @@ type jobStatus struct {
Status, Error string Status, Error string
} }
// status returns the status of job id, or job_not_found's code. // status returns the status of job id. Any other answer fails the test, so
// that a refusal never reads as the job's status.
func (d *daemon) status(t *testing.T, id string) jobStatus { func (d *daemon) status(t *testing.T, id string) jobStatus {
t.Helper() t.Helper()
req, _ := http.NewRequest(http.MethodGet, d.base+"/api/v1/jobs/"+id, nil) req, _ := http.NewRequest(http.MethodGet, d.base+"/api/v1/jobs/"+id, nil)
@@ -111,11 +112,8 @@ func (d *daemon) status(t *testing.T, id string) jobStatus {
jobStatus jobStatus
Code string Code string
} }
if err := json.NewDecoder(resp.Body).Decode(&st); err != nil { if err := json.NewDecoder(resp.Body).Decode(&st); err != nil || resp.StatusCode != http.StatusOK {
t.Fatal(err) t.Fatalf("GET /api/v1/jobs/%s = %d %s, %v", id, resp.StatusCode, st.Code, err)
}
if st.Code != "" {
return jobStatus{Status: st.Code}
} }
return st.jobStatus return st.jobStatus
} }
+14 -2
View File
@@ -99,12 +99,14 @@ func TestServeEndToEnd(t *testing.T) {
body := fmt.Sprintf(` body := fmt.Sprintf(`
[api] [api]
secret = %q secret = %q
[webserver]
rate_limit = %d
[printer] [printer]
address = "127.0.0.1" address = "127.0.0.1"
port = %d port = %d
[log] [log]
level = "error" level = "error"
`, secret, printer.addr.Port) `, secret, testRateLimit, printer.addr.Port)
if err := os.WriteFile(path, []byte(body), 0o600); err != nil { if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -163,6 +165,9 @@ level = "error"
return false return false
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("GET /api/v1/jobs/%s = %d", queued.ID, resp.StatusCode)
}
var st struct{ Status string } var st struct{ Status string }
_ = json.NewDecoder(resp.Body).Decode(&st) _ = json.NewDecoder(resp.Body).Decode(&st)
return st.Status == "done" return st.Status == "done"
@@ -229,11 +234,18 @@ func waitFor(t *testing.T, cond func() bool) {
t.Fatal("condition not met within 10s") t.Fatal("condition not met within 10s")
} }
// testRateLimit is the API rate limit of the daemons under test. waitFor
// polls every 20 ms, so on a slow runner a wait of a second or two spends
// the default budget of 60 requests a minute, and every later request in
// that minute is refused. No test comes near this limit.
const testRateLimit = 1_000_000
// testConfig returns a valid config for a printer at port, logging errors // testConfig returns a valid config for a printer at port, logging errors
// only. // only, with an API rate limit the tests cannot reach.
func testConfig(port int) *config.Config { func testConfig(port int) *config.Config {
cfg := config.Default() cfg := config.Default()
cfg.API.Secret = "end-to-end-secret-end-to-end-secret!" cfg.API.Secret = "end-to-end-secret-end-to-end-secret!"
cfg.WebServer.RateLimit = testRateLimit
cfg.Printer.Address, cfg.Printer.Port = "127.0.0.1", port cfg.Printer.Address, cfg.Printer.Port = "127.0.0.1", port
cfg.Log.Level = "error" cfg.Log.Level = "error"
return &cfg return &cfg