gateway tests: an unrouted 504 test waits for its held report before it ends
TestUnroutedUnknownHoldAnsweredSooner failed on mote (10-29) with "TempDir RemoveAll cleanup: unlinkat …/magpie/held: directory not empty". The 504 is answered first and the held report is written after it (unrouted.go), so a test that returns on the 504 alone races the write against its TempDir's removal. TestUnroutedHeldReportSaved already waited for the route's Held; the three others that end on an unrouted 504 (UnknownHoldAnsweredSooner, RequestShownThenAnswered, MostLeavesOutMasking) now wait too, through heldSaved, for any probe/text route naming its report (once let go, the request may begin a route of its own beside the one shown). Run (mote): the four unrouted/held tests -count=3 with a 300ms sleep injected before writeHeld: ok; full ./internal/gateway in the previous commit's record. Broken by hand: not reproduced red. With the injected sleep the old tests still pass, since the late write lands after RemoveAll and recreates the folder rather than racing it; the cause is from the log and the code, not a forced red. At this head (both commits rebased on origin/mainadc618bbf), on mote: go vet, GOOS=windows go vet and GOOS=linux go vet -tags nogui of ./internal/gateway ./internal/provider clean; go test -count=1 ./internal/provider ok; ./internal/gateway -run 'Factory|Refus|Policy|Unrouted|Held' ok. The full ./internal/gateway run (ok, 768s) was at the earlier base96a703a59. Rebased once more ontofc43c69e5(Codex effort change: codex_backend, decide, effort_update, gateway, quiet, responses; none of the files here) after that run; not run again on it.
This commit is contained in:
@@ -136,6 +136,28 @@ func TestUnroutedUnknownHoldAnsweredSooner(t *testing.T) {
|
||||
if r.err != nil || r.code != http.StatusGatewayTimeout || !strings.Contains(r.body, "without routing it to any provider") {
|
||||
t.Fatalf("held request answered %d %q %v", r.code, r.body, r.err)
|
||||
}
|
||||
heldSaved(t, s)
|
||||
}
|
||||
|
||||
// heldSaved waits for the report of the request s answered 504 for
|
||||
// being held before routing: the 504 goes first and the report is saved
|
||||
// after it, so a test that returns on the 504 alone has its HOME removed
|
||||
// under the write ("TempDir RemoveAll cleanup: … magpie/held: directory
|
||||
// not empty" on mote, 10-29).
|
||||
func heldSaved(t *testing.T, s *Server) {
|
||||
t.Helper()
|
||||
for deadline := time.Now().Add(10 * time.Second); ; time.Sleep(10 * time.Millisecond) {
|
||||
// any route: once let go, the request may have begun one of
|
||||
// its own beside the one shown while it was held
|
||||
for _, r := range routesOf(s, "probe/text") {
|
||||
if r.Held != "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("the held request's report was never saved: %+v", routesOf(s, "probe/text"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A body still arriving (an image over a slow link) is a known wait: a
|
||||
@@ -369,6 +391,7 @@ func TestUnroutedRequestShownThenAnswered(t *testing.T) {
|
||||
if len(rs) != 1 || !rs[0].Done || rs[0].Status != http.StatusGatewayTimeout || !strings.Contains(rs[0].Error, "without routing") {
|
||||
t.Fatalf("the held request's route: %+v", rs)
|
||||
}
|
||||
heldSaved(t, s)
|
||||
}
|
||||
|
||||
// One shown while it waited gives way to its own route once routed: the
|
||||
@@ -460,6 +483,7 @@ func TestUnroutedMostLeavesOutMasking(t *testing.T) {
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("a request held after masking was never answered")
|
||||
}
|
||||
heldSaved(t, s)
|
||||
}
|
||||
|
||||
// A request another magpie passed on is shown, while it waits to be
|
||||
|
||||
Reference in New Issue
Block a user