HDDS-16170. Intermittent failure in TestSnapshotDiffManager#testLoadJobsOnStartUp - #11014
Draft
smengcl wants to merge 1 commit into
Draft
HDDS-16170. Intermittent failure in TestSnapshotDiffManager#testLoadJobsOnStartUp#11014smengcl wants to merge 1 commit into
smengcl wants to merge 1 commit into
Conversation
…obsOnStartUp testLoadJobsOnStartUp stubs generateSnapshotDiffReport with a doAnswer that writes DONE to the DB inside the answer body, then waits on verify(spy, atLeast(1)).generateSnapshotDiffReport(...) before reading the job back and asserting DONE. Mockito records an invocation before it runs the stubbed answer, so the verify wait can pass while the answer is still executing and has not yet persisted DONE. The subsequent DB read then observes the original IN_PROGRESS and the assertion fails intermittently (expected: <DONE> but was: <IN_PROGRESS>). Wait on the observable end state the test asserts instead: poll the persisted job status until it is DONE. This closes the window between Mockito recording the invocation and the answer writing DONE, making the test deterministic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent failure in TestSnapshotDiffManager#testLoadJobsOnStartUp by changing the test’s synchronization strategy to wait on the persisted job status rather than a Mockito invocation, eliminating a race between method entry and the stubbed doAnswer completing its DB write.
Changes:
- Replace
attempt(verify(...))with polling ofgetSnapshotDiffJobFromDb(...).getStatus()until it reachesDONE. - Add explanatory comments documenting why Mockito-based waiting was flaky in this scenario.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Generated-by: Claude Code (Opus 4.8)
What changes were proposed in this pull request?
TestSnapshotDiffManager#testLoadJobsOnStartUpfails intermittently withexpected: <DONE> but was: <IN_PROGRESS>.The test stubs
generateSnapshotDiffReportwith adoAnswerthat writesDONEto the DB inside the answer body, callsloadJobsOnStartUp(), then waits withattempt(() -> verify(spy, atLeast(1)).generateSnapshotDiffReport(...))before reading the job back and assertingDONE.Mockito records an invocation before it runs the stubbed answer, so the
verify(...)wait can pass as soon as the worker thread entersgenerateSnapshotDiffReport, while the answer is still running and has not yet persistedDONE. The main thread then reads the job and observes the originalIN_PROGRESS, so the assertion fails.The fix waits on the actual observable end state the test asserts: it polls
getSnapshotDiffJobFromDb(...).getStatus()until it isDONE, instead of waiting on the Mockito invocation. This is deterministic by construction because the read the assertion depends on is exactly what is waited on. No production code changes.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16170
How was this patch tested?
Ran the affected test locally against the change:
A single green run cannot prove non-flakiness, so the fix is made deterministic by construction: the wait polls the same persisted job status that the subsequent assertion reads, closing the window between Mockito recording the invocation and the stubbed answer writing
DONEto the DB.