Skip to content

tests: fix race condition on macOS#2242

Merged
dunglas merged 2 commits intomainfrom
fix/race-mac
Mar 6, 2026
Merged

tests: fix race condition on macOS#2242
dunglas merged 2 commits intomainfrom
fix/race-mac

Conversation

@dunglas
Copy link
Member

@dunglas dunglas commented Mar 6, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 6, 2026 14:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Caddy integration tests to reduce macOS flakiness by ensuring the test server is actually accepting connections after InitServer, addressing transient SO_REUSEPORT routing to a shutting-down listener.

Changes:

  • Introduce an initServer helper that calls tester.InitServer and then polls the HTTP endpoint to avoid early “connection reset by peer” failures.
  • Replace direct tester.InitServer(...) calls throughout the file with initServer(...).
  • Remove now-redundant waitForServerReady(...) calls in tests that previously needed extra readiness polling.
Comments suppressed due to low confidence (1)

caddy/caddy_test.go:43

  • initServer returns silently if all 10 polling attempts fail, so tests may continue with the server still unavailable and fail later with less actionable errors. Consider failing the test after the retry loop (e.g., t.Fatalf/require.FailNow) and include the last error/URL in the message so readiness issues are surfaced immediately.
	url := "http://localhost:" + testPort
	client := &http.Client{Timeout: 1 * time.Second}
	for range 10 {
		resp, err := client.Get(url)
		if err == nil {
			require.NoError(t, resp.Body.Close())

			return
		}

		time.Sleep(100 * time.Millisecond)
	}
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dunglas dunglas merged commit 87556c4 into main Mar 6, 2026
31 checks passed
@dunglas dunglas deleted the fix/race-mac branch March 6, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants