TestModuleMaxRequests verifies that regular (non-worker) PHP threads restart after reaching max_requests by checking debug logs for restart messages.
(t *testing.T)
| 15 | // TestModuleMaxRequests verifies that regular (non-worker) PHP threads restart |
| 16 | // after reaching max_requests by checking debug logs for restart messages. |
| 17 | func 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. |
nothing calls this directly
no test coverage detected