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.
This commit is contained in:
yetone
2026-11-01 15:33:35 +08:00
parent 4a4a82cd49
commit 647323409e
+6 -3
View File
@@ -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)
}()