Skip to content

Fix flaky Ersatz empty response body test with @Retry#15485

Merged
jamesfredley merged 1 commit into7.0.xfrom
fix/ersatz-roundtrip-connection-reset
Mar 6, 2026
Merged

Fix flaky Ersatz empty response body test with @Retry#15485
jamesfredley merged 1 commit into7.0.xfrom
fix/ersatz-roundtrip-connection-reset

Conversation

@jamesfredley
Copy link
Contributor

Summary

  • Add @Retry(count = 2, delay = 200) to the flaky MicronautErsatzRoundtripSpec."full roundtrip: ersatz mocks empty response body" test

Problem

This test intermittently fails on CI with:

HttpClientException: Client 'grails-self': Error occurred reading HTTP response: Connection reset

Observed in Groovy Joint Validation Build run 22598688156.

Root Cause

The ErsatzServer is created per test method (@AutoCleanup, not @Shared) on a fixed port (19876). Between test methods, the server is stopped and a new one is started on the same port. The Micronaut @Client(id = 'grails-self') HTTP client maintains a connection pool, so stale connections from the previous test's Ersatz instance can cause Connection reset when reused against the new server.

Fix

Add Spock's @Retry annotation scoped to HttpClientException only, so only transient connection issues trigger a retry (up to 2 retries with 200ms delay). This follows the standard pattern for CI-flaky network tests without masking real failures.

The 'ersatz mocks empty response body' test intermittently fails with
HttpClientException: Connection reset. This occurs because the Ersatz
server is recreated per test method on a fixed port (19876), and the
Micronaut @client connection pool may hold stale connections from the
previous test's server instance.

Add @Retry(count = 2, delay = 200) scoped to HttpClientException so
only transient connection issues trigger a retry.

Assisted-by: Claude Code <Claude@Claude.ai>
@jamesfredley jamesfredley self-assigned this Mar 3, 2026
@jamesfredley jamesfredley marked this pull request as ready for review March 3, 2026 17:46
Copilot AI review requested due to automatic review settings March 3, 2026 17:46
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

Reduces CI flakiness in the Micronaut/Ersatz integration test suite by retrying a single intermittently failing roundtrip test that can hit transient connection resets due to pooled HTTP connections.

Changes:

  • Import Spock’s spock.lang.Retry.
  • Add @Retry(count = 2, delay = 200, exceptions = [HttpClientException]) to the “empty response body” roundtrip test.

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

@jamesfredley jamesfredley merged commit b55862b into 7.0.x Mar 6, 2026
36 checks passed
@jamesfredley jamesfredley deleted the fix/ersatz-roundtrip-connection-reset branch March 6, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants