Skip to content

Commit 1d8235d

Browse files
committed
test: wait for transition goroutines to exit
TestTransitionThreadsWhileDoingRequests spawned transition goroutines that read mainThread.state via thread.shutdown(). isDone.Store(true) signalled them to stop but the test returned without waiting, so they could still be running when the next test's initPHPThreads wrote a fresh mainThread.state, producing a -race failure on macOS.
1 parent 5fe2014 commit 1d8235d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

phpmainthread_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
9595
t.Cleanup(Shutdown)
9696

9797
var (
98-
isDone atomic.Bool
99-
wg sync.WaitGroup
98+
isDone atomic.Bool
99+
wg sync.WaitGroup
100+
transitionsWG sync.WaitGroup
100101
)
101102

102103
numThreads := 10
@@ -122,8 +123,10 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
122123

123124
// try all possible permutations of transition, transition every ms
124125
transitions := allPossibleTransitions(worker1Path, worker2Path)
126+
transitionsWG.Add(numThreads)
125127
for i := range numThreads {
126128
go func(thread *phpThread, start int) {
129+
defer transitionsWG.Done()
127130
for {
128131
for j := start; j < len(transitions); j++ {
129132
if isDone.Load() {
@@ -158,6 +161,9 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
158161
// we are finished as soon as all 1000 requests are done
159162
wg.Wait()
160163
isDone.Store(true)
164+
// wait for transition goroutines to exit before Shutdown to avoid them
165+
// racing with a subsequent test's initPHPThreads via mainThread.state
166+
transitionsWG.Wait()
161167
}
162168

163169
func TestFinishBootingAWorkerScript(t *testing.T) {

0 commit comments

Comments
 (0)