From 647323409e888968c11a6f7ade7b11a573127057 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 15:33:35 +0800 Subject: [PATCH] gui tests: TestColdTurnsTaken asks once the warm-up holds its turn (#4510) The test closed `asked` and asked at once, while the warm-up's goroutine might not have taken its turn yet. The page then took the turn first, a right order, and the test called it "answered while the warm-up's step read". Its t.Fatal left the step blocked holding the turn, so with -count above 1 every later run waited to the timeout. The step now closes `holding` once it has its turn, and the page asks after that. sessions.go is unchanged. Run (mote): go test -tags nogui ./internal/gui -run 'TestColdTurnsTaken$' -count=200 -cpu 1,2,8 -race ok (35.7s). Broken by hand: coldTurn not taking a turn turns it red at once. --- internal/gui/warm_turns_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/gui/warm_turns_test.go b/internal/gui/warm_turns_test.go index fb6e81f65..dd8a4351c 100644 --- a/internal/gui/warm_turns_test.go +++ b/internal/gui/warm_turns_test.go @@ -16,7 +16,10 @@ func TestColdTurnsTaken(t *testing.T) { coldTurns.over.Store(false) t.Cleanup(func() { coldTurnsTaken = false; coldTurns.over.Store(false) }) var inStep, inPage, both atomic.Int32 - asked, release := make(chan struct{}), make(chan struct{}) + // the warm-up holds its turn before the page asks: asked at once, the + // page could take the turn before the warm-up's goroutine ran, a + // right order the test called wrong (#4510) + holding, release := make(chan struct{}), make(chan struct{}) page := coldTurn(func(http.ResponseWriter, *http.Request) { inPage.Add(1) if inStep.Load() > 0 { @@ -33,7 +36,7 @@ func TestColdTurnsTaken(t *testing.T) { warmUp(func() { inStep.Add(1) defer inStep.Add(-1) - <-asked + close(holding) <-release }, func() { inStep.Add(1) @@ -43,9 +46,9 @@ func TestColdTurnsTaken(t *testing.T) { } }) }() + <-holding answered := make(chan struct{}) go func() { - close(asked) ask() close(answered) }()