Skip to content
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

Fix test in TransportGetAllocationStatsActionTests #124902

Conversation

JeremyDahlgren
Copy link
Contributor

Saw this while reading/testing code for #124898.

testReturnsOnlyRequestedStats() was using
EnumSet.copyOf(randomSubsetOf(Metric.values().length, Metric.values())) which will always return all of the metrics.
The code was expecting Metric.ALLOCATIONS and Metric.FS to sometimes not be in the returned set.
This change uses an explicit list of EnumSets to cover the range of scenarios expected in the test code.

@JeremyDahlgren JeremyDahlgren added >non-issue :Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) Team:Distributed Coordination Meta label for Distributed Coordination team labels Mar 14, 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.

Nice catch!

EnumSet.of(Metric.ALLOCATIONS),
EnumSet.of(Metric.FS),
EnumSet.noneOf(Metric.class),
EnumSet.allOf(Metric.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, no reason not to test several meaningful cases here. Could we also add back a random subset too, only done properly this time:

EnumSet.copyOf(randomSubsetOf(EnumSet.allOf(Metric.class)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like copyOf() needs at least one element, so I added:
EnumSet.copyOf(randomSubsetOf(between(1, Metric.values().length), EnumSet.allOf(Metric.class)))

@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests and removed >non-issue labels Mar 14, 2025
testReturnsOnlyRequestedStats() was using
EnumSet.copyOf(randomSubsetOf(Metric.values().length, Metric.values()))
which will always return all of the metrics.  The code was expecting
Metric.ALLOCATIONS and Metric.FS to sometimes not be in the returned set.
This change uses an explicit list of EnumSets to cover the range of
scenarios expected in the test code.
@JeremyDahlgren JeremyDahlgren force-pushed the jdahlgren-fix-testReturnsOnlyRequestedStats branch from ff901b8 to f1f6827 Compare March 14, 2025 18:38
Copy link
Contributor

@mhl-b mhl-b left a comment

Choose a reason for hiding this comment

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

LGTM

@JeremyDahlgren JeremyDahlgren marked this pull request as ready for review March 17, 2025 20:16
@elasticsearchmachine
Copy link
Collaborator

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

@JeremyDahlgren JeremyDahlgren merged commit 92290aa into elastic:main Mar 17, 2025
17 checks passed
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Mar 18, 2025
testReturnsOnlyRequestedStats() was using
EnumSet.copyOf(randomSubsetOf(Metric.values().length, Metric.values()))
which will always return all of the metrics.  The code was expecting
Metric.ALLOCATIONS and Metric.FS to sometimes not be in the returned set.
This change uses an explicit list of EnumSets to cover the range of
scenarios expected in the test code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) Team:Distributed Coordination Meta label for Distributed Coordination team >test Issues or PRs that are addressing/adding tests v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants