Skip to content

Mock correct method in SegmentReplicationTargetServiceTests#20746

Merged
andrross merged 1 commit intoopensearch-project:mainfrom
andrross:srtst-fix
Mar 12, 2026
Merged

Mock correct method in SegmentReplicationTargetServiceTests#20746
andrross merged 1 commit intoopensearch-project:mainfrom
andrross:srtst-fix

Conversation

@andrross
Copy link
Copy Markdown
Member

@andrross andrross commented Feb 27, 2026

The test was mocking the wrong overload of startReplication(), which caused the real method to be invoke and would result in a failure + retry. The test assertion would then be racing with the retry and fail if the retry invoked startReplication() a second time.

Resolves #15829

Check List

  • Functionality includes testing.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

The test was mocking the wrong overload of startReplication(), which
caused the real method to be invoke and would result in a failure +
retry. The test assertion would then be racing with the retry and fail
if the retry invoked startReplication() a second time.

Signed-off-by: Andrew Ross <andrross@amazon.com>
@andrross andrross requested a review from a team as a code owner February 27, 2026 19:26
@github-actions github-actions bot added >test-failure Test failure from CI, local build, etc. autocut flaky-test Random test failure that succeeds on second run labels Feb 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Redundant Mock

The existing doReturn mock for the 3-argument startReplication(any(), any(), any()) on line 676 may now be redundant or conflicting since the correct 4-argument overload is now mocked on line 677. It should be verified whether the 3-argument mock is still needed or can be removed to avoid confusion.

doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), any());
doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), anyBoolean(), any());

@github-actions
Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Remove redundant unused stub

The first doReturn stub for the 3-argument startReplication is now unused since the
test only verifies the 4-argument overload. Having an unused stub can cause
confusion and may trigger strict mocking warnings or failures. Remove the redundant
3-argument stub to keep the test clean and accurate.

server/src/test/java/org/opensearch/indices/replication/SegmentReplicationTargetServiceTests.java [676-677]

-doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), any());
 doReturn(mock(SegmentReplicationTarget.class)).when(service).startReplication(any(), any(), anyBoolean(), any());
Suggestion importance[1-10]: 5

__

Why: The 3-argument startReplication stub on line 676 is not verified in this test (only the 4-argument overload is verified), making it redundant. Removing it improves test clarity, though it's a minor cleanup with no functional impact.

Low

@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 54e38ce: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 54e38ce: null

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 54e38ce: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

✅ Gradle check result for 54e38ce: SUCCESS

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.24%. Comparing base (59be6ae) to head (54e38ce).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #20746      +/-   ##
============================================
- Coverage     73.29%   73.24%   -0.05%     
+ Complexity    72088    72049      -39     
============================================
  Files          5794     5794              
  Lines        329733   329733              
  Branches      47577    47577              
============================================
- Hits         241664   241504     -160     
- Misses        68612    68825     +213     
+ Partials      19457    19404      -53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andrross andrross merged commit 2e60e60 into opensearch-project:main Mar 12, 2026
49 of 56 checks passed
@andrross andrross deleted the srtst-fix branch March 12, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autocut flaky-test Random test failure that succeeds on second run skip-changelog >test-failure Test failure from CI, local build, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOCUT] Gradle Check Flaky Test Report for SegmentReplicationTargetServiceTests

2 participants