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

Function TestAddModuleWorkerViaAdminApi

caddy/admin_test.go:274–347  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

272}
273
274func TestAddModuleWorkerViaAdminApi(t *testing.T) {
275 // Initialize a server with admin API enabled
276 tester := caddytest.NewTester(t)
277 tester.InitServer(`
278 {
279 skip_install_trust
280 admin localhost:2999
281 http_port `+testPort+`
282 }
283
284 localhost:`+testPort+` {
285 route {
286 root ../testdata
287 php
288 }
289 }
290 `, "caddyfile")
291
292 // Get initial debug state to check number of workers
293 initialDebugState := getDebugState(t, tester)
294 initialWorkerCount := 0
295 for _, thread := range initialDebugState.ThreadDebugStates {
296 if strings.HasPrefix(thread.Name, "Worker PHP Thread") {
297 initialWorkerCount++
298 }
299 }
300
301 // Create a Caddyfile configuration with a module worker
302 workerConfig := `
303 {
304 skip_install_trust
305 admin localhost:2999
306 http_port ` + testPort + `
307 }
308
309 localhost:` + testPort + ` {
310 route {
311 root ../testdata
312 php {
313 worker ../testdata/worker-with-counter.php 1
314 }
315 }
316 }
317 `
318
319 // Send the configuration to the admin API
320 adminUrl := "http://localhost:2999/load"
321 r, err := http.NewRequest("POST", adminUrl, bytes.NewBufferString(workerConfig))
322 assert.NoError(t, err)
323 r.Header.Set("Content-Type", "text/caddyfile")
324 resp := tester.AssertResponseCode(r, http.StatusOK)
325 defer func() { require.NoError(t, resp.Body.Close()) }()
326
327 // Get the updated debug state to check if the worker was added
328 updatedDebugState := getDebugState(t, tester)
329 updatedWorkerCount := 0
330 workerFound := false
331 filename, _ := fastabs.FastAbs("../testdata/worker-with-counter.php")

Callers

nothing calls this directly

Calls 4

FastAbsFunction · 0.92
getDebugStateFunction · 0.85
SetMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected