Fix flaky Ersatz empty response body test with @Retry#15485
Merged
jamesfredley merged 1 commit into7.0.xfrom Mar 6, 2026
Merged
Fix flaky Ersatz empty response body test with @Retry#15485jamesfredley merged 1 commit into7.0.xfrom
jamesfredley merged 1 commit into7.0.xfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
jdaugherty
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@Retry(count = 2, delay = 200)to the flakyMicronautErsatzRoundtripSpec."full roundtrip: ersatz mocks empty response body"testProblem
This test intermittently fails on CI with:
Observed in Groovy Joint Validation Build run 22598688156.
Root Cause
The
ErsatzServeris 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 causeConnection resetwhen reused against the new server.Fix
Add Spock's
@Retryannotation scoped toHttpClientExceptiononly, 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.