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

Function TestHotReload

caddy/hotreload_test.go:20–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestHotReload(t *testing.T) {
21 const topic = "https://frankenphp.dev/hot-reload/test"
22
23 u := "/.well-known/mercure?topic=" + url.QueryEscape(topic)
24
25 tmpDir := t.TempDir()
26 indexFile := filepath.Join(tmpDir, "index.php")
27
28 tester := caddytest.NewTester(t)
29 // caddytest's default 5s http.Client.Timeout is too tight for the
30 // SSE roundtrip below on slow CI runners (notably emulated armv7).
31 // 30s keeps the test bounded so a real regression fails fast.
32 tester.Client.Timeout = 30 * time.Second
33 tester.InitServer(`
34 {
35 debug
36 skip_install_trust
37 admin localhost:2999
38 }
39
40 http://localhost:`+testPort+` {
41 mercure {
42 transport local
43 subscriber_jwt TestKey
44 anonymous
45 }
46
47 php_server {
48 root `+tmpDir+`
49 hot_reload {
50 topic `+topic+`
51 watch `+tmpDir+`/*.php
52 }
53 }
54 `, "caddyfile")
55
56 var connected, received sync.WaitGroup
57
58 connected.Add(1)
59 received.Go(func() {
60 cx, cancel := context.WithCancel(t.Context())
61 req, _ := http.NewRequest(http.MethodGet, "http://localhost:"+testPort+u, nil)
62 req = req.WithContext(cx)
63 resp := tester.AssertResponseCode(req, http.StatusOK)
64
65 connected.Done()
66
67 var receivedBody strings.Builder
68
69 buf := make([]byte, 1024)
70 for {
71 n, err := resp.Body.Read(buf)
72 if n > 0 {
73 receivedBody.Write(buf[:n])
74 }
75 if strings.Contains(receivedBody.String(), "index.php") {
76 cancel()
77

Callers

nothing calls this directly

Calls 3

CloseMethod · 0.80
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected