upwatch: hold a seeding torrent app for one line test, then put its limit back exactly (R-1250)
gates / gates (push) Successful in 1m22s

When the agent waits for quiet and qBittorrent or Transmission runs: record the limit first,
hold at 1 KiB/s, ask the agent for a test on request, put the old limit back (deferred; a
household change during the test stays). Start-up puts back a limit a killed controller left;
the 50 % rule skips while a hold record exists. Commit only.
This commit is contained in:
2026-10-24 13:19:07 +02:00
parent bddc477e22
commit 046b808792
10 changed files with 789 additions and 33 deletions
@@ -34,3 +34,31 @@ func TestLineTestDecodesAndAnOlderAgentIs404(t *testing.T) {
t.Fatalf("an older agent must answer a typed 404, got %v", err)
}
}
// R-1250: the request decodes its outcome, waiting_for_quiet decodes, and the request outlasts the client's own
// timeout (the agent answers after about 55 s; the client's default is 15 s).
func TestLineTestRunOutlastsTheClientTimeout(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("GET /host/line-test", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`{"ok":true,"data":{"present":false,"waiting_for_quiet":true}}`))
})
mux.HandleFunc("POST /host/line-test/run", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(300 * time.Millisecond)
_, _ = w.Write([]byte(`{"ok":true,"data":{"ok":true,"mbps":93.5,"runs_mbps":[92,93.5,93]}}`))
})
s := httptest.NewTLSServer(mux)
defer s.Close()
c := clientFor(t, s, strings.TrimPrefix(s.URL, "https://"))
st, err := c.LineTest(context.Background())
if err != nil || st.Present || !st.WaitingForQuiet {
t.Fatalf("GET = %+v %v, want present:false waiting_for_quiet:true", st, err)
}
c.hc.Timeout = 100 * time.Millisecond // stands in for the 15 s default against a 55 s answer
if _, err := c.post(context.Background(), "/host/line-test/run", struct{}{}); err == nil {
t.Fatal("the plain POST should time out here — the seam does not test anything")
}
res, err := c.LineTestRun(context.Background())
if err != nil || !res.OK || res.Mbps != 93.5 || len(res.RunsMbps) != 3 {
t.Fatalf("LineTestRun = %+v %v", res, err)
}
}