-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix test in TransportGetAllocationStatsActionTests
#124902
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
There was a problem hiding this 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) |
There was a problem hiding this comment.
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)))
There was a problem hiding this comment.
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)))
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.
ff901b8 to
f1f6827
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
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.
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.
Saw this while reading/testing code for #124898.
testReturnsOnlyRequestedStats()was usingEnumSet.copyOf(randomSubsetOf(Metric.values().length, Metric.values()))which will always return all of the metrics.The code was expecting
Metric.ALLOCATIONSandMetric.FSto 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.