From 3a1ade9729996d81b67beaf4570250f9772fa10b Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 10 Oct 2026 17:26:26 +0800 Subject: [PATCH] gateway: TestReasoningLoopIsAskedAgain takes the two tries' let-go in either order The gateway cancels the looping try and asks again at once, so the next try can end and report before the first try's handler sees its write fail. macOS CI got them in that order (ddd4f431's run: "let go: the looping try false, the next true"). The next try only ever reports false, and the looping one reports false only after 20s unreleased, so one true and one false in any order still proves the looping try was let go. Run: reproduced CI's message on the old test by sleeping 300ms before each let-go of true; the new test passes with that delay and without it (-run 'TestReasoningLoop|TestLoop' -count=5). --- internal/gateway/loop_guard_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/gateway/loop_guard_test.go b/internal/gateway/loop_guard_test.go index e37b331a1..b5f9746f0 100644 --- a/internal/gateway/loop_guard_test.go +++ b/internal/gateway/loop_guard_test.go @@ -533,8 +533,13 @@ func TestReasoningLoopIsAskedAgain(t *testing.T) { if n := v.asked.Load(); n != 2 { t.Fatalf("the vendor was asked %d times, want 2", n) } - if first, second := <-v.letGo, <-v.letGo; !first || second { - t.Fatalf("let go: the looping try %v, the next %v", first, second) + // The looping try is let go (true) and the next ends whole + // (false), in whichever order the two handlers get there: the + // next can finish before the first sees its request cancelled. + // Only the next try sends false at once; the looping one sends + // false only after 20s unreleased. + if a, b := <-v.letGo, <-v.letGo; a == b { + t.Fatalf("let go: %v and %v, want the looping try let go and the next not", a, b) } }) }