Fix flaky KubernetesTCPRemoteCommitProviderTest - #153
Merged
Conversation
fetchDynamicAddresses() closes the client returned by kubernetesClient() (try-with-resources), so handing out the shared client of the mock server made every refresh after the first one fail with an already-closed client. DynamicTCPRemoteCommitProvider.endConfiguration() runs the updater once synchronously and then schedules it with an initial delay of 0, so a second run always races the assertions: if it won, all addresses were removed again and the test saw 0 instead of 2. Hand out a fresh client per invocation, as the production implementation does, and assert that the addresses survive the scheduled refreshes.
ilgrosso
approved these changes
Aug 20, 2026
solomax
approved these changes
Aug 20, 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.
KubernetesTCPRemoteCommitProviderTest.addressesfails intermittently on CI with:Root cause
KubernetesTCPRemoteCommitProvider.fetchDynamicAddresses()closes the client it obtains:In production that is fine, since
kubernetesClient()builds a new client on every call. The test, however, overrides it to returnserver.getClient()— the shared client of the mock server — so the first fetch closes it and every later fetch fails and returns an empty list.That matters because
DynamicTCPRemoteCommitProvider.endConfiguration()runs the updater once synchronously and then schedules it with an initial delay of0:So a second run always fires immediately on the timer thread, gets an empty address list, and the removal step drops both addresses again. Whether the assertion reads
_addressesbefore or after that run is a pure race — green on a fast machine, flaky on CI.Reproducible deterministically by inserting a
Thread.sleep(500)before the assertion: it then fails withexpected:<2> but was:<0>on every run.Change
server.getKubernetesMockServer().createClient()), exactly as the production implementation doesmock will drop all IPs if test will run too longcomment — the mock never dropped anything, the closed client didVerification
mvn -pl openjpa-kubernetes test-> passes, 4 consecutive runsaddresses:175->assertAddresses:180 expected:<2> but was:<0>Note
Production code is untouched. The redundant immediate second run in
DynamicTCPRemoteCommitProvider.endConfiguration()(initial delay0right after a synchronousrun()) is harmless once the fetches no longer fail, but changing the initial delay to_cacheDurationMilliswould be a sensible follow-up.No JIRA key on the commit yet — happy to reword the subject if you want this filed under a specific issue.