TestWorkerMaxRequestsHighConcurrency verifies max_requests works under concurrent load.
(t *testing.T)
| 220 | |
| 221 | // TestWorkerMaxRequestsHighConcurrency verifies max_requests works under concurrent load. |
| 222 | func TestWorkerMaxRequestsHighConcurrency(t *testing.T) { |
| 223 | const maxRequests = 10 |
| 224 | const totalRequests = 200 |
| 225 | |
| 226 | runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, _ int) { |
| 227 | var ( |
| 228 | mu sync.Mutex |
| 229 | instanceIDs = make(map[string]int) |
| 230 | ) |
| 231 | var wg sync.WaitGroup |
| 232 | |
| 233 | for i := 0; i < totalRequests; i++ { |
| 234 | wg.Add(1) |
| 235 | go func() { |
| 236 | defer wg.Done() |
| 237 | body, resp := testGet("http://example.com/worker-counter-persistent.php", handler, t) |
| 238 | assert.Equal(t, 200, resp.StatusCode) |
| 239 | |
| 240 | mu.Lock() |
| 241 | parts := strings.Split(body, ",") |
| 242 | if len(parts) == 2 { |
| 243 | instanceID := strings.TrimPrefix(parts[0], "instance:") |
| 244 | instanceIDs[instanceID]++ |
| 245 | } |
| 246 | mu.Unlock() |
| 247 | }() |
| 248 | } |
| 249 | wg.Wait() |
| 250 | |
| 251 | t.Logf("instances: %d", len(instanceIDs)) |
| 252 | assert.Greater(t, len(instanceIDs), 4, "workers should have restarted multiple times") |
| 253 | |
| 254 | for id, count := range instanceIDs { |
| 255 | assert.LessOrEqual(t, count, maxRequests, |
| 256 | fmt.Sprintf("instance %s handled %d requests, exceeding max_requests=%d", id, count, maxRequests)) |
| 257 | } |
| 258 | }, &testOptions{ |
| 259 | workerScript: "worker-counter-persistent.php", |
| 260 | nbWorkers: 4, |
| 261 | nbParallelRequests: 1, |
| 262 | initOpts: []frankenphp.Option{frankenphp.WithNumThreads(5), frankenphp.WithMaxRequests(maxRequests)}, |
| 263 | }) |
| 264 | } |
nothing calls this directly
no test coverage detected