Skip to content

Conversation

DonalEvans
Copy link
Contributor

@DonalEvans DonalEvans commented Oct 16, 2025

The existing randomValueOtherThan() method uses Objects.equals() to determine if a randomly generated object is equal to the provided argument. This approach does not work as expected for arrays, however, since two arrays with identical contents will not be considered equal by Objects.equals(). See #136652

This commit introduces randomArrayOtherThan() methods for Object arrays and primitive arrays and converts all places in the code that were previously passing arrays into randomValueOtherThan() to use the new array-specific methods

The existing randomValueOtherThan() method uses Objects.equals() to
determine if a randomly generated object is equal to the provided
argument. This approach does not work as expected for arrays, however,
since two arrays with identical contents will not be considered equal by
Objects.equals(). See elastic#136652

This commit introduces randomValueOtherThanArray() methods for Object
arrays and primitive arrays and converts all places in the code that
were previously passing arrays into randomValueOtherThan() to use the
new array-specific methods
@DonalEvans DonalEvans added >test Issues or PRs that are addressing/adding tests v9.3.0 labels Oct 16, 2025
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Oct 16, 2025
@DonalEvans DonalEvans added the Team:ML Meta label for the ML team label Oct 16, 2025
@elasticsearchmachine elasticsearchmachine removed the Team:ML Meta label for the ML team label Oct 16, 2025
@DonalEvans DonalEvans added :ml Machine learning Team:ML Meta label for the ML team labels Oct 16, 2025
@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Oct 16, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Copy link
Contributor

@przemekwitek przemekwitek left a comment

Choose a reason for hiding this comment

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

LGTM

/**
* helper to get a random value in a certain range that's different from the input, for object arrays
*/
public static <T> T[] randomValueOtherThanArray(T[] input, Supplier<T[]> randomSupplier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would make sense to rename this method to randomArrayOtherThan or similar to avoid the impression that the method is actually not returning array?
Maybe it's not an issue because the randomValueOtherThanMany also sounds a bit strange to me.
I'm leaving it up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a better name, yeah

@DonalEvans DonalEvans changed the title Introduce ESTestCase.randomValueOtherThanArray() methods Introduce ESTestCase.randomArrayOtherThan() methods Oct 16, 2025
@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Oct 16, 2025
Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou left a comment

Choose a reason for hiding this comment

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

LGTM Good stuff!

@DonalEvans DonalEvans merged commit 1758533 into elastic:main Oct 17, 2025
35 checks passed
@DonalEvans DonalEvans deleted the random-value-other-than-arrays branch October 17, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:ml Machine learning serverless-linked Added by automation, don't add manually Team:ML Meta label for the ML team >test Issues or PRs that are addressing/adding tests v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants