-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy paththreadregular_test.go
More file actions
63 lines (56 loc) 路 1.7 KB
/
Copy paththreadregular_test.go
File metadata and controls
63 lines (56 loc) 路 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package frankenphp
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRegularRequestChanIsCreatedBeforeInitRuns(t *testing.T) {
require.NotNil(t, regularRequestChan,
"a request dispatched between the start of Init and the first thread being attached "+
"must queue on a real channel: sending on a nil channel blocks forever, "+
"even after the channel variable is later assigned")
}
func TestRequestsQueuedBeforeThreadsAreReadyAreHandedOver(t *testing.T) {
regularThreadMu.Lock()
savedThreads := regularThreads
regularThreads = nil
regularThreadMu.Unlock()
savedMaxWaitTime := maxWaitTime.Swap(0)
savedScaleChan := scaleChan
scaleChan = nil
t.Cleanup(func() {
regularThreadMu.Lock()
regularThreads = savedThreads
regularThreadMu.Unlock()
maxWaitTime.Store(savedMaxWaitTime)
scaleChan = savedScaleChan
})
const requests = 5
errChans := make([]chan error, requests)
for i := range errChans {
fc := &frankenPHPContext{done: make(chan any)}
errChan := make(chan error, 1)
go func() {
errChan <- handleRequestWithRegularPHPThreads(contextHolder{ctx: context.Background(), frankenPHPContext: fc})
}()
errChans[i] = errChan
}
for i := 0; i < requests; i++ {
select {
case ch := <-regularRequestChan:
ch.frankenPHPContext.closeContext()
case <-time.After(5 * time.Second):
t.Fatalf("only %d of %d queued requests were handed over", i, requests)
}
}
for i, errChan := range errChans {
select {
case err := <-errChan:
assert.NoError(t, err, "request %d", i)
case <-time.After(5 * time.Second):
t.Fatalf("dispatcher for request %d did not return after the request was handled", i)
}
}
}