-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Describe the bug
When working on another PR I faced a bug where the comparison tests intermittently failed depending on the type of the returned numbers and the compared ones (actual VS expected) with a ClassCastException when the numeric values are of different boxed types, e.g.
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long
This occurs in the four comparison assertions (gt, gte, lt and lte) when one side is parsed as Integer and the other as Long (or similarly for Float vs Double).
Proposed fix:
Update Assertion.convertActualValue to normalize mixed numeric types to a common upper type.
This ensures consistent behavior in test assertions, especially for large values (e.g., values > Integer.MAX_VALUE).
Related component
Search
To Reproduce
Run a Yaml Rest test file that compares a small number (int) to a large one (long) returned from a search response (or vice versa)
---
setup:
- do:
indices.create:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
big:
type: long
- do:
index:
index: test
id: "1"
body:
big: 4294967296 # > Integer.MAX_VALUE
- do:
indices.refresh:
index: test
---
"gt with Integer expected vs Long actual triggers parsing bug":
- do:
get:
index: test
id: "1"
# expected is the literal 2 (Integer), actual is 4294967296 (Long).
# Current Assertion.convertActualValue tries Integer.parseInt("4294967296") and throws.
- gt: { _source.big: 2 }
Expected behavior
Assertions should normalize numeric types so both sides are comparable without throwing. For example, promote to Long when comparing Integer vs Long, and to Double when comparing floating types.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status