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

Function TestAutoWorkerConfig

caddy/caddy_test.go:956–1049  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

954}
955
956func TestAutoWorkerConfig(t *testing.T) {
957 var wg sync.WaitGroup
958 tester := caddytest.NewTester(t)
959 initServer(t, tester, `
960 {
961 skip_install_trust
962 admin localhost:2999
963 http_port `+testPort+`
964 https_port 9443
965 metrics
966
967 frankenphp {
968 worker ../testdata/index.php
969 }
970 }
971
972 localhost:`+testPort+` {
973 route {
974 php {
975 root ../testdata
976 }
977 }
978 }
979 `, "caddyfile")
980
981 workerName, _ := fastabs.FastAbs("../testdata/index.php")
982 workerName = escapeMetricLabel(workerName)
983
984 // Make some requests
985 for i := range 10 {
986 wg.Add(1)
987 go func(i int) {
988 tester.AssertGetResponse(fmt.Sprintf("http://localhost:"+testPort+"/index.php?i=%d", i), http.StatusOK, fmt.Sprintf("I am by birth a Genevese (%d)", i))
989 wg.Done()
990 }(i)
991 }
992 wg.Wait()
993
994 // Fetch metrics
995 resp, err := http.Get("http://localhost:2999/metrics")
996 require.NoError(t, err, "failed to fetch metrics")
997 t.Cleanup(func() {
998 require.NoError(t, resp.Body.Close())
999 })
1000
1001 // Read and parse metrics
1002 metrics := new(bytes.Buffer)
1003 _, err = metrics.ReadFrom(resp.Body)
1004 require.NoError(t, err, "failed to read metrics")
1005
1006 numThreads := getNumThreads(t, tester)
1007 cpus := strconv.Itoa(numThreads)
1008 workers := strconv.Itoa(numThreads - 1)
1009
1010 // Check metrics
1011 expectedMetrics := `
1012 # HELP frankenphp_total_threads Total number of PHP threads
1013 # TYPE frankenphp_total_threads counter

Callers

nothing calls this directly

Calls 6

FastAbsFunction · 0.92
initServerFunction · 0.85
escapeMetricLabelFunction · 0.85
getNumThreadsFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected