Skip to content

Conversation

@liuguoqingfz
Copy link
Contributor

@liuguoqingfz liuguoqingfz commented Dec 17, 2025

Description

Fix a flaky test where there is a test expectation mismatch.
the test asserts that the thrown InvalidIndexTemplateException message contains:
"specifies a context which cannot be used without enabling"
But the current code path throws a different message:
"specifies a context which is not loaded on the cluster."
It typically happens when the validation order changed or a different validation branch triggers first instead of “context feature disabled”, it now fails earlier/later with “context not loaded”.

Related Issues

Resolves #19058

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

Summary by CodeRabbit

  • Tests
    • Enhanced exception message validation in metadata index template tests for improved assertion accuracy.

✏️ Tip: You can customize this high-level summary in your review settings.

@liuguoqingfz liuguoqingfz requested a review from a team as a code owner December 17, 2025 01:56
@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 Dec 17, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Walkthrough

The changes refactor two test assertions in MetadataIndexTemplateServiceTests to store exception messages in local variables and use them in assertions instead of making repeated calls to ex.getMessage(). This improves assertion clarity and addresses flaky test behavior by ensuring consistent message validation.

Changes

Cohort / File(s) Change Summary
Test assertion refactoring
server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java
Introduced local msg variable to store exception messages in two test methods; updated assertions to use the variable instead of repeated ex.getMessage() calls; first assertion validates both "specifies a context which cannot be used without enabling" and "specifies a context which is not loaded on the cluster" conditions.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

flaky-test

Suggested reviewers

  • sachinpkale
  • saratvemulapalli
  • andrross
  • dbwiddis
  • cwperks
  • msfroh

Poem

🐰 With messages now caught and held tight,
No flaky assertions to cause a fright,
A local variable brings clarity clear,
The tests shall be steady, the results sincere!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description provides context on the test flakiness, explains the root cause (expectation mismatch between two possible exception messages), and references the related issue #19058. All key sections are present.
Linked Issues check ✅ Passed The PR addresses the flaky test failure in testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled by updating assertions to accept both possible exception messages, directly resolving the objective stated in linked issue #19058.
Out of Scope Changes check ✅ Passed All changes are limited to updating test assertions in MetadataIndexTemplateServiceTests.java to handle both possible exception messages, which is directly in scope for fixing the flaky test reported in issue #19058.
Title check ✅ Passed The title 'Fix flaky test in MetadataIndexTemplateServiceTests' directly and clearly describes the main change - fixing a flaky test in the specific test file modified in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

ex.getMessage().contains("specifies a context which cannot be used without enabling")
"Invalid exception message." + msg,
msg.contains("specifies a context which cannot be used without enabling")
|| msg.contains("specifies a context which is not loaded on the cluster")
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be the wrong assertion for testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled? I think it would be better to understand why this is being thrown to prevent it.

Copy link
Member

@cwperks cwperks Dec 17, 2025

Choose a reason for hiding this comment

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

Maybe the failing test needs to be annotated with @LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)?

@github-actions
Copy link
Contributor

❌ Gradle check result for cacc32a: 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?

@sandeshkr419 sandeshkr419 changed the title Fix a flaky test for issue 19058 Fix flaky test in MetadataIndexTemplateServiceTests Dec 22, 2025
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 >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 MetadataIndexTemplateServiceTests

2 participants