MCPcopy Create free account
hub / github.com/php/frankenphp / TestWorkerMetrics

Function TestWorkerMetrics

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

Source from the content-addressed store, hash-verified

758}
759
760func TestWorkerMetrics(t *testing.T) {
761 var wg sync.WaitGroup
762 tester := caddytest.NewTester(t)
763 initServer(t, tester, `
764 {
765 skip_install_trust
766 admin localhost:2999
767 http_port `+testPort+`
768 https_port 9443
769 metrics
770
771 frankenphp {
772 worker ../testdata/index.php 2
773 }
774 }
775
776 localhost:`+testPort+` {
777 route {
778 php {
779 root ../testdata
780 }
781 }
782 }
783
784 example.com:`+testPort+` {
785 route {
786 php {
787 root ../testdata
788 }
789 }
790 }
791 `, "caddyfile")
792
793 workerName, _ := fastabs.FastAbs("../testdata/index.php")
794 workerName = escapeMetricLabel(workerName)
795
796 // Make some requests
797 for i := range 10 {
798 wg.Add(1)
799 go func(i int) {
800 tester.AssertGetResponse(fmt.Sprintf("http://localhost:"+testPort+"/index.php?i=%d", i), http.StatusOK, fmt.Sprintf("I am by birth a Genevese (%d)", i))
801 wg.Done()
802 }(i)
803 }
804 wg.Wait()
805
806 // Fetch metrics
807 resp, err := http.Get("http://localhost:2999/metrics")
808 require.NoError(t, err, "failed to fetch metrics")
809 t.Cleanup(func() {
810 require.NoError(t, resp.Body.Close())
811 })
812
813 // Read and parse metrics
814 metrics := new(bytes.Buffer)
815 _, err = metrics.ReadFrom(resp.Body)
816 require.NoError(t, err, "failed to read metrics")
817

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