Fix bug "Assertion framework(Yaml Rest test): numeric comparison fails when comparing Integer vs Long (or Float vs Double)"#19376
Conversation
|
❌ Gradle check result for e258963: 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? |
|
Hi @sandeshkr419 |
sandeshkr419
left a comment
There was a problem hiding this comment.
Thanks for fixing this and refactoring the code. I do have some clarifying questions.
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/Assertion.java
Show resolved
Hide resolved
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java
Outdated
Show resolved
Hide resolved
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java
Outdated
Show resolved
Hide resolved
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java
Outdated
Show resolved
Hide resolved
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java
Show resolved
Hide resolved
...ramework/src/main/java/org/opensearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java
Outdated
Show resolved
Hide resolved
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java
Outdated
Show resolved
Hide resolved
|
❌ Gradle check result for 596a2b6: 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? |
|
@sandeshkr419 Can you take another look at this? |
|
❌ Gradle check result for 596a2b6: 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? |
|
❌ Gradle check result for 596a2b6: 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? |
596a2b6 to
3ca23d2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19376 +/- ##
============================================
- Coverage 73.30% 73.29% -0.01%
- Complexity 71732 71756 +24
============================================
Files 5793 5793
Lines 328056 328110 +54
Branches 47245 47256 +11
============================================
+ Hits 240476 240495 +19
+ Misses 68264 68255 -9
- Partials 19316 19360 +44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This PR is stalled because it has been open for 30 days with no activity. |
…ls when comparing Integer vs Long (or Float vs Double) Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com>
Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com>
Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com>
3ca23d2 to
321fb54
Compare
Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com>
|
❌ Gradle check result for 5ddde84: 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? |
|
Hi @andrross |
Can you please fix the changelog file conflict, the new commit should start the Gradle check CI run again. We can move forward once all the CI's are green. Thanks |
|
❌ Gradle check result for 5ddde84: 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? |
WalkthroughA structural refactoring of the YAML REST test assertion framework extracts ordering comparison logic (greater-than, less-than variants) into a shared abstract base class, consolidating numeric type normalization and comparison handling. Additionally, the base Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Key areas requiring attention:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
test/framework/src/test/java/org/opensearch/test/rest/yaml/section/AssertionTests.java (1)
114-114: Consider adding tests forGreaterThanEqualToAssertionandLessThanOrEqualToAssertion.While the shared
OrderingAssertionbase class means these assertions use the same comparison logic, adding at least one cross-type test per assertion type would improve test coverage completeness and ensure all relation operators work correctly.test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java (1)
127-137: ConsiderBigDecimal/BigIntegerhandling.The current implementation converts all non-floating numbers to
Long, which could lose precision forBigIntegerorBigDecimalvalues. However, since JSON parsing typically yieldsInteger/Long/Double, this is unlikely to be an issue in practice for YAML REST tests.If
BigDecimal/BigIntegersupport is needed in the future, consider handling them explicitly:private static Tuple<Object, Object> normalizePair(Object a, Object b) { if (a instanceof Number aNum && b instanceof Number bNum) { + // BigDecimal/BigInteger: compare directly without conversion + if (a instanceof java.math.BigDecimal || b instanceof java.math.BigDecimal + || a instanceof java.math.BigInteger || b instanceof java.math.BigInteger) { + return Tuple.tuple(a, b); + } boolean isFloating = aNum instanceof Float || aNum instanceof Double || bNum instanceof Float || bNum instanceof Double;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
CHANGELOG.md(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/Assertion.java(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/GreaterThanAssertion.java(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/GreaterThanEqualToAssertion.java(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/LessThanAssertion.java(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java(1 hunks)test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java(1 hunks)test/framework/src/test/java/org/opensearch/test/rest/yaml/section/AssertionTests.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
- GitHub Check: gradle-check
- GitHub Check: assemble (25, windows-latest)
- GitHub Check: assemble (25, ubuntu-latest)
- GitHub Check: assemble (25, ubuntu-24.04-arm)
- GitHub Check: assemble (21, ubuntu-latest)
- GitHub Check: assemble (21, windows-latest)
- GitHub Check: assemble (21, ubuntu-24.04-arm)
- GitHub Check: Analyze (java)
- GitHub Check: precommit (25, windows-latest)
- GitHub Check: precommit (25, ubuntu-24.04-arm)
- GitHub Check: detect-breaking-change
- GitHub Check: precommit (25, macos-15)
- GitHub Check: precommit (25, macos-15-intel)
- GitHub Check: precommit (21, windows-2025, true)
- GitHub Check: precommit (21, ubuntu-24.04-arm)
- GitHub Check: precommit (21, macos-15)
- GitHub Check: precommit (21, windows-latest)
- GitHub Check: precommit (21, ubuntu-latest)
- GitHub Check: precommit (25, ubuntu-latest)
- GitHub Check: precommit (21, macos-15-intel)
- GitHub Check: Mend Security Check
🔇 Additional comments (10)
CHANGELOG.md (1)
97-97: LGTM!The changelog entry is correctly placed under the "Fixed" section and accurately describes the bug fix for numeric type comparison failures in the YAML REST test assertion framework.
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/GreaterThanEqualToAssertion.java (1)
45-62: LGTM!The refactoring cleanly delegates to the new
OrderingAssertionbase class. Therelation()anderrorMessage()template methods are properly implemented, and the parsing logic is now consolidated.test/framework/src/test/java/org/opensearch/test/rest/yaml/section/AssertionTests.java (2)
70-87: LGTM!Good coverage of cross-type numeric scenarios for
GreaterThanAssertion. The tests validate that mixed Integer/Long and Float/Double comparisons work correctly without throwingClassCastException.
97-114: LGTM!The
LessThanAssertiontests properly validate both successful cross-type comparisons and failure scenarios. UsingexpectThrows(AssertionError.class, ...)confirms that comparison failures now produceAssertionErrorinstead ofClassCastException, which was the core bug being fixed.test/framework/src/main/java/org/opensearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java (1)
45-62: LGTM!The refactoring is consistent with the other ordering assertion classes. The previous review comment about passing the
Relation.LTEenum directly has been addressed—the implementation now uses theRelationenum throughout.test/framework/src/main/java/org/opensearch/test/rest/yaml/section/GreaterThanAssertion.java (1)
44-61: LGTM!The refactoring eliminates code duplication by extending
OrderingAssertion. The implementation is consistent with the other ordering assertion classes and follows the template method pattern correctly.test/framework/src/main/java/org/opensearch/test/rest/yaml/section/LessThanAssertion.java (1)
45-62: LGTM!Clean refactoring that properly delegates to the shared
OrderingAssertionbase class. Therelation()anderrorMessage()implementations are correct for less-than semantics, and the parsing correctly uses the sharedparseOrderingAssertionmechanism.test/framework/src/main/java/org/opensearch/test/rest/yaml/section/OrderingAssertion.java (3)
30-33: LGTM!Well-structured abstract base class that properly extends
Assertionand establishes the contract for ordering assertion subclasses.
56-72: LGTM!The shared parsing logic is well-implemented with proper validation that the expected value is
Comparable. The factory pattern allows clean instantiation of concrete assertion types.
74-109: LGTM!The
doAssertimplementation correctly chainsconvertActualValue→normalizePairbefore comparison. The switch expression handles allRelationcases exhaustively, and theClassCastExceptioncatch provides a useful fallback error message.
test/framework/src/main/java/org/opensearch/test/rest/yaml/section/Assertion.java
Show resolved
Hide resolved
|
❌ Gradle check result for cc5b742: 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? |
|
❌ Gradle check result for cc5b742: 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? |
…s when comparing Integer vs Long (or Float vs Double)" (opensearch-project#19376) * Fix bug: Assertion framework (Yaml Rest test): numeric comparison fails when comparing Integer vs Long (or Float vs Double) Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * class rename Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * some small changes based on the PR review Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * update change log Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> --------- Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> Co-authored-by: Lamine Idjeraoui <lidjeraoui@apple.com>
…s when comparing Integer vs Long (or Float vs Double)" (opensearch-project#19376) * Fix bug: Assertion framework (Yaml Rest test): numeric comparison fails when comparing Integer vs Long (or Float vs Double) Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * class rename Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * some small changes based on the PR review Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * update change log Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> --------- Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> Co-authored-by: Lamine Idjeraoui <lidjeraoui@apple.com>
…s when comparing Integer vs Long (or Float vs Double)" (opensearch-project#19376) * Fix bug: Assertion framework (Yaml Rest test): numeric comparison fails when comparing Integer vs Long (or Float vs Double) Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * class rename Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * some small changes based on the PR review Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> * update change log Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> --------- Signed-off-by: Lamine Idjeraoui <lidjeraoui@apple.com> Co-authored-by: Lamine Idjeraoui <lidjeraoui@apple.com>
Resolves #19323
The numerical comparison classes (gt, gte, lt and lte) share more than 90% of the code. Refactored the 4 classes by extracted the common code into a super class.
Updated the convertActualValue method to normalize mixed numeric types to a common upper type.
Check List
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
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.