Skip to content

Fix flaky SegmentReplicationIT remote build test - #3550

Open
navaneethbv wants to merge 2 commits into
opensearch-project:mainfrom
navaneethbv:codex/fix-segment-replication-2726
Open

Fix flaky SegmentReplicationIT remote build test#3550
navaneethbv wants to merge 2 commits into
opensearch-project:mainfrom
navaneethbv:codex/fix-segment-replication-2726

Conversation

@navaneethbv

@navaneethbv navaneethbv commented Sep 4, 2026

Copy link
Copy Markdown

Description

Re-enable SegmentReplicationIT in the remote index build integration test suite now that remote builds terminate when their Lucene merge is aborted by #3488.

Remove the fixed five-second sleep from testSearchOnReplicas_whenIndexHasDeletedDocs_thenSuccess.
The primary KNN assertion remains immediate so the test still detects an invalid remote graph instead of waiting for a later merge to hide it.
Only the replica assertion uses assertBusy, because segment replication is asynchronous and the assertion should wait for the actual observable condition rather than an arbitrary delay.

This is a smaller alternative to #3397 and, unlike that change, removes the Gradle exclusion so the remote index build workflow exercises the regression.

Local validation:

  • ./gradlew spotlessCheck --no-build-cache
  • ./gradlew compileTestJava -x cmakeJniLib -x buildJniLib --no-build-cache
  • JAVA_HOME="/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home" CPPFLAGS="-I/opt/homebrew/opt/libomp/include" LDFLAGS="-L/opt/homebrew/opt/libomp/lib" ./gradlew :integTest --tests 'org.opensearch.knn.index.SegmentReplicationIT.testSearchOnReplicas_whenIndexHasDeletedDocs_thenSuccess' -PnumNodes=2 --no-build-cache

The focused two-node integration test passed locally in 4 minutes 40 seconds after installing Homebrew GCC and libomp.
The remote index build variant additionally requires the containerized remote builder and LocalStack, so the repository's remote index build workflow remains the end-to-end validation gate for the reported configuration.

Related Issues

Resolves #2726

Check List

  • New functionality includes testing.
  • New functionality has been documented. (Not applicable, test-only change.)
  • API changes companion pull request created. (Not applicable, no API change.)
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created. (Not applicable, no user-facing change.)

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.

Signed-off-by: Navaneeth Rao <navaneethbv@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit fd8fd4b)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit fd8fd4b

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.20%. Comparing base (70deae2) to head (fd8fd4b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #3550   +/-   ##
=========================================
  Coverage     83.20%   83.20%           
  Complexity     4631     4631           
=========================================
  Files           469      469           
  Lines         16572    16572           
  Branches       2181     2181           
=========================================
  Hits          13788    13788           
  Misses         1959     1959           
  Partials        825      825           

☔ View full report in Codecov by Harness.
📢 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.

Comment on lines +81 to +86
assertBusy(() -> {
Response replicaSearchResponse = performSearch(INDEX_NAME, queryBuilder.toString(), "preference=_replica");
String replicaResponseBody = EntityUtils.toString(replicaSearchResponse.getEntity());
List<KNNResult> replicaResults = parseSearchResponse(replicaResponseBody, FIELD_NAME);
assertEquals(docsInIndex - deleteDocs, replicaResults.size());
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen in the case when segment replication is really struck due to bugs? how we will get out of the busy loop here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertBusy is bounded and won't retry indefinitely. The default implementation retries for up to 10 seconds. If segment replication is genuinely stuck and the replica never reaches the expected state, the assertion will continue failing, and assertBusy will eventually propagate the failure, causing the test to fail. The intent here is only to tolerate the asynchronous replication delay instead of relying on the fixed 5-second sleep.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution provided in the pR: #3397 was better than this, since it avoids the fixed delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Flaky Test org.opensearch.knn.index.SegmentReplicationIT.testSearchOnReplicas_whenIndexHasDeletedDocs_thenSuccess

2 participants