Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions phpmainthread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
t.Cleanup(Shutdown)

var (
isDone atomic.Bool
wg sync.WaitGroup
isDone atomic.Bool
wg sync.WaitGroup
transitionsWG sync.WaitGroup
)

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

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

func TestFinishBootingAWorkerScript(t *testing.T) {
Expand Down
Loading