MCPcopy Index your code
hub / github.com/php/frankenphp / TestModuleMaxRequests

Function TestModuleMaxRequests

maxrequests_regular_test.go:17–42  ·  view source on GitHub ↗

TestModuleMaxRequests verifies that regular (non-worker) PHP threads restart after reaching max_requests by checking debug logs for restart messages.

(t *testing.T)

Source from the content-addressed store, hash-verified

15// TestModuleMaxRequests verifies that regular (non-worker) PHP threads restart
16// after reaching max_requests by checking debug logs for restart messages.
17func TestModuleMaxRequests(t *testing.T) {
18 const maxRequests = 5
19 const totalRequests = 30
20
21 var buf syncBuffer
22 logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug}))
23
24 runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, _ int) {
25 for i := 0; i < totalRequests; i++ {
26 body, resp := testGet("http://example.com/index.php", handler, t)
27 assert.Equal(t, 200, resp.StatusCode)
28 assert.Contains(t, body, "I am by birth a Genevese")
29 }
30
31 restartCount := strings.Count(buf.String(), "max requests reached, restarting thread")
32 t.Logf("Thread restarts observed: %d", restartCount)
33 assert.GreaterOrEqual(t, restartCount, 2,
34 "with maxRequests=%d and %d requests on 2 threads, at least 2 restarts should occur", maxRequests, totalRequests)
35 }, &testOptions{
36 logger: logger,
37 initOpts: []frankenphp.Option{
38 frankenphp.WithNumThreads(2),
39 frankenphp.WithMaxRequests(maxRequests),
40 },
41 })
42}
43
44// TestModuleMaxRequestsConcurrent verifies max_requests works under concurrent load
45// in module mode. All requests must succeed despite threads restarting.

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
WithNumThreadsFunction · 0.92
WithMaxRequestsFunction · 0.92
runTestFunction · 0.85
testGetFunction · 0.85

Tested by

no test coverage detected