-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 failure in AppendProcessorTests.testAppendingToListWithDuplicatesDisallowed #62385
Conversation
Pinging @elastic/es-core-features (:Core/Features/Ingest) |
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 left a comment about this, it was hard for me to understand exactly what the code was doing without staring at it for a few minutes
List<String> nonexistingValues = new ArrayList<>(); | ||
for (int i = 0; i < nonexistingValuesSize; i++) { | ||
boolean valueExists = true; | ||
while (valueExists) { |
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.
This seems really confusing to me, I think we could do the same thing with:
int nonexistingValueSize = randomIntBetween(0, 10);
// generate n new values
Set<String> newValues = Stream.generate(() -> randomAlphaOfLengthBetween(1, 10)).limit(nonexistingValueSize).collect(Collectors.toSet());
// create a set using the new values, making sure there are no overlapping values already present in the existing values
Set<String> nonexistingValues = Sets.difference(newValues, new HashSet<>(existingValues));
Using the while loop for this is a bit overkill, I think Set
s makes it easier to avoid duplicates
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.
Thanks, @dakrone. I simplified the test as you suggested.
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, thanks Dan
Thanks, @dakrone! |
One of the test cases purported to test the appending of unique values to an existing list but the list of unique values to be appended was randomly generated and would occasionally contain values already in the list (see example test seed below). This fix ensures that the list of unique values never contains any values in the existing list.
Example of a test seed that would fail:
./gradlew ':modules:ingest-common:test' --tests "org.elasticsearch.ingest.common.AppendProcessorTests.testAppendingToListWithDuplicatesDisallowed" -Dtests.seed=AC5D435485DE7219