-
Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy paththread_api_test.go
More file actions
88 lines (69 loc) · 1.65 KB
/
thread_api_test.go
File metadata and controls
88 lines (69 loc) · 1.65 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package frankenphp
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestThreadReturnsNilWhenNotRunning(t *testing.T) {
// Before Init(), Thread() should return nil
thread, ok := Thread(0)
assert.Nil(t, thread)
assert.False(t, ok)
}
func TestThreadReturnsValidThread(t *testing.T) {
t.Cleanup(Shutdown)
require.NoError(t, Init(
WithNumThreads(2),
WithMaxThreads(2),
))
// Thread 0 should exist after init
thread, ok := Thread(0)
assert.True(t, ok)
assert.NotNil(t, thread)
}
func TestThreadReturnsNilForInvalidIndex(t *testing.T) {
t.Cleanup(Shutdown)
require.NoError(t, Init(
WithNumThreads(2),
WithMaxThreads(2),
))
// Index beyond thread count should return nil
thread, ok := Thread(999)
assert.Nil(t, thread)
assert.False(t, ok)
}
func TestThreadExposesRequestDuringExecution(t *testing.T) {
t.Cleanup(Shutdown)
require.NoError(t, Init(
WithNumThreads(2),
WithMaxThreads(2),
))
handler := func(w http.ResponseWriter, r *http.Request) {
req, err := NewRequestWithContext(r,
WithRequestDocumentRoot(testDataPath, false),
)
assert.NoError(t, err)
err = ServeHTTP(w, req)
assert.NoError(t, err)
}
req := httptest.NewRequest("GET", "http://localhost/echo.php", nil)
w := httptest.NewRecorder()
handler(w, req)
assert.Equal(t, http.StatusOK, w.Code)
}
func TestPHPThreadPin(t *testing.T) {
t.Cleanup(Shutdown)
require.NoError(t, Init(
WithNumThreads(2),
WithMaxThreads(2),
))
thread, ok := Thread(0)
require.True(t, ok)
// Pin should not panic
data := "test data"
assert.NotPanics(t, func() {
thread.Pin(&data)
})
}