Skip to content

Commit f4d2336

Browse files
authored
Merge branch 'main' into fix/opcache-safe-reset
2 parents 08c9d60 + 1d8235d commit f4d2336

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)