Skip to content

Add Cluster Allocation Explain API Tests #130381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

joshua-adams-1
Copy link
Contributor

Adds tests for the cluster/allocation/explain API for when non-integer values are passed as the integer-expected shard parameter. This change does not modify the cluster/allocation/explain API itself, but adds tests for current, expected behaviour. This PR is a pre-requisite for a change modifying the behaviour of the API when a float is passed, resolving a comment on #129342

Adds tests for the `cluster/allocation/explain` API for when non-integer
 values are passed as the integer expected shard parameter. This change
 does not modify
 the `cluster/allocation/explain` API itself.
Changed `cluster shard allocation explanation test with double shard
value` to 0 replicas
Changed double shard value from 2.1... to 1.1...
@joshua-adams-1 joshua-adams-1 added :Distributed Coordination/Distributed A catch all label for anything in the Distributed Coordination area. Please avoid if you can. >non-issue labels Jul 1, 2025
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

IMO this is a rather excessive way to check a single line of code which calls PARSER.declareInt. If you think the tests for AbstractObjectParser do not adequately cover these corner cases then we should address that there, but I don't think it makes sense to test all the failure paths and other corners through the API like this. There are 351 other production calls to that one method that we'd have to test similarly after setting this precedent, and yet I'm struggling to imagine how any of these tests might fail.

@joshua-adams-1 joshua-adams-1 marked this pull request as ready for review July 1, 2025 11:23
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Jul 1, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@joshua-adams-1
Copy link
Contributor Author

There are 2 reasons for adding these tests:

  1. We currently allow the user to enter a float value for a field we've marked as integer. There was a comment on #129342 to change this, and if I did that without having tests like this in place, nothing would break and we wouldn't be notified.
  2. Just because there are tests in place for the Parser, doesn't mean we shouldn't have tests in place for the class using the parser. Changes made by someone in the ClusterAllocationExplainRequest class are currently untested. I also think it's important to explicitly state what we expect the API to do in situations where non-integer types are passed in fields expecting integers, rather than it being assumed because it's mentioned in the documentation

@DaveCTurner
Copy link
Contributor

I see ok, yeah just seems a bit odd to nail down the current behaviour even though we don't really care about the behaviour in these corner cases today.

Just because there are tests in place for the Parser, doesn't mean we shouldn't have tests in place for the class using the parser.

True, but it doesn't mean that we should have such tests either :) If you extrapolate that line of thinking you end up having to test everything at every level through every other layer of abstraction which is clearly infeasible. So there's some judgement required about whether such tests are worth it. Often they are, under-testing is more common than over-testing, but both extremes are problematic in their own ways.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

@joshua-adams-1
Copy link
Contributor Author

I understand what you're saying about over-testing, and if we were to extrapolate this to all APIs, then I appreciate this would be a massive bloat to our testing suite! My logic this time was 1) I am, by nature, a big advocate of tests and will always ere on the side of more tests, a line of thinking I'm happy to re-evaluate as I learn more about the codebase and 2) we're directly changing the functionality tested by these tests so in this instance it seemed a necessary addition so that I can verify my new code works as expected. Happy to discuss anything further offline! Thank you for the review

@joshua-adams-1 joshua-adams-1 merged commit 5c8c001 into elastic:main Jul 1, 2025
32 checks passed
@joshua-adams-1 joshua-adams-1 deleted the cluster-allocation-explain-extra-tests branch July 1, 2025 13:02
mridula-s109 pushed a commit to mridula-s109/elasticsearch that referenced this pull request Jul 3, 2025
Add Cluster Allocation Explain API Tests

Adds tests for the `cluster/allocation/explain` API for when non-integer values are passed as the integer expected shard parameter. This change does not modify the `cluster/allocation/explain` API itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Distributed A catch all label for anything in the Distributed Coordination area. Please avoid if you can. >non-issue Team:Distributed Coordination Meta label for Distributed Coordination team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants