Skip to content

Commit

Permalink
Fix rare serialization failure in SuggestTests (elastic#101014)
Browse files Browse the repository at this point in the history
SuggestTests uses a fairly recursive way to create its test item. Those can end
up with an CompletionSuggestion.Entry.Option that have a "rank" field set to
something other than the bwc default of -1. The test still tries to test the
serialization roundtrip to a random transport version down to TransportVersions.MINIMUM_COMPATIBLE
which is currently at V_7_17_0, but the rank field serialization fails for
anything below V_8_8_0. In reality however, suggester options shouldn't contain search
hits with a set rank field, so simples way to avoid it is checking the randomly
created test item for those cases and correct them before running the test.

Closes elastic#95607
  • Loading branch information
cbuescher authored Nov 8, 2023
1 parent e786cfa commit 5ef9f76
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public void testMergingSuggestionOptions() {
assertTrue(option1.collateMatch());
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/95607")
public void testSerialization() throws IOException {
TransportVersion bwcVersion = TransportVersionUtils.randomVersionBetween(
random(),
Expand All @@ -248,6 +247,22 @@ public void testSerialization() throws IOException {
);

final Suggest suggest = createTestItem();
// suggest is disallowed when using rank, but the randomization rarely sets it
// we need to make sure CompletionSuggestion$Entry$Option doesn't have "rank" set
// because for some older versions it will not serialize.
if (bwcVersion.before(TransportVersions.V_8_8_0)) {
for (CompletionSuggestion s : suggest.filter(CompletionSuggestion.class)) {
for (CompletionSuggestion.Entry entry : s.entries) {
List<CompletionSuggestion.Entry.Option> options = entry.getOptions();
for (CompletionSuggestion.Entry.Option o : entry.getOptions()) {
if (o.getHit() != null) {
o.getHit().setRank(-1);
}
}
}
}
}

final Suggest bwcSuggest;

NamedWriteableRegistry registry = new NamedWriteableRegistry(new SearchModule(Settings.EMPTY, emptyList()).getNamedWriteables());
Expand Down

0 comments on commit 5ef9f76

Please sign in to comment.