initServer initializes a Caddy test server and waits for it to be ready. After InitServer, it polls the server to handle a race condition on macOS where SO_REUSEPORT can briefly route connections to the old listener being shut down, resulting in "connection reset by peer".
(t *testing.T, tester *caddytest.Tester, config string, format string)
| 26 | // SO_REUSEPORT can briefly route connections to the old listener being shut down, |
| 27 | // resulting in "connection reset by peer". |
| 28 | func initServer(t *testing.T, tester *caddytest.Tester, config string, format string) { |
| 29 | t.Helper() |
| 30 | tester.InitServer(config, format) |
| 31 | |
| 32 | client := &http.Client{Timeout: 1 * time.Second} |
| 33 | require.Eventually(t, func() bool { |
| 34 | resp, err := client.Get("http://localhost:" + testPort) |
| 35 | if err != nil { |
| 36 | return false |
| 37 | } |
| 38 | |
| 39 | require.NoError(t, resp.Body.Close()) |
| 40 | |
| 41 | return true |
| 42 | }, 5*time.Second, 100*time.Millisecond, "server failed to become ready") |
| 43 | } |
| 44 | |
| 45 | var testPort = "9080" |
| 46 |
no test coverage detected