From 5ef9f76b8134036b607515914d949081f32fbaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 8 Nov 2023 10:01:08 +0100 Subject: [PATCH] Fix rare serialization failure in SuggestTests (#101014) 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 #95607 --- .../search/suggest/SuggestTests.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java b/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java index b6fa1e236a843..d209f15a641f5 100644 --- a/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java +++ b/server/src/test/java/org/elasticsearch/search/suggest/SuggestTests.java @@ -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(), @@ -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 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());