From 07f65e978a0ec900abc01701cf8e6bca649ea1cf Mon Sep 17 00:00:00 2001 From: Panagiotis Bailis Date: Tue, 24 Jun 2025 19:31:09 +0300 Subject: [PATCH] Fixing race condition in DynamicMappingIT when checking for updates in mappings (#129931) --- muted-tests.yml | 3 -- .../index/mapper/DynamicMappingIT.java | 49 ++++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 4987c698354c..46e00e16b1d7 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -565,9 +565,6 @@ tests: - class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests method: testExistsQueryMinimalMapping issue: https://github.com/elastic/elasticsearch/issues/129911 -- class: org.elasticsearch.index.mapper.DynamicMappingIT - method: testDenseVectorDynamicMapping - issue: https://github.com/elastic/elasticsearch/issues/129928 # Examples: # diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java index 7318c3dd17ec..91861310d05c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -920,19 +920,27 @@ public class DynamicMappingIT extends ESIntegTestCase { client().index( new IndexRequest("test").source("vector_int8", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD - 1, 0.0, 5.0).toArray()) + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) ).get(); client().index( new IndexRequest("test").source("vector_bbq", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray()) + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) ).get(); - Map mappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test") - .get() - .mappings() - .get("test") - .sourceAsMap(); - assertTrue(new WriteField("properties.vector_int8", () -> mappings).exists()); - assertTrue(new WriteField("properties.vector_int8.index_options.type", () -> mappings).get(null).toString().equals("int8_hnsw")); - assertTrue(new WriteField("properties.vector_bbq", () -> mappings).exists()); - assertTrue(new WriteField("properties.vector_bbq.index_options.type", () -> mappings).get(null).toString().equals("bbq_hnsw")); + + assertBusy(() -> { + Map mappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test") + .get() + .mappings() + .get("test") + .sourceAsMap(); + + assertTrue(new WriteField("properties.vector_int8", () -> mappings).exists()); + assertTrue( + new WriteField("properties.vector_int8.index_options.type", () -> mappings).get(null).toString().equals("int8_hnsw") + ); + assertTrue(new WriteField("properties.vector_bbq", () -> mappings).exists()); + assertTrue(new WriteField("properties.vector_bbq.index_options.type", () -> mappings).get(null).toString().equals("bbq_hnsw")); + }); } public void testBBQDynamicMappingWhenFirstIngestingDoc() throws Exception { @@ -954,14 +962,19 @@ public class DynamicMappingIT extends ESIntegTestCase { assertTrue(new WriteField("properties.vector", () -> mappings).exists()); assertFalse(new WriteField("properties.vector.index_options.type", () -> mappings).exists()); - client().index(new IndexRequest("test").source("vector", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray())) - .get(); - Map updatedMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test") - .get() - .mappings() - .get("test") - .sourceAsMap(); - assertTrue(new WriteField("properties.vector", () -> updatedMappings).exists()); - assertTrue(new WriteField("properties.vector.index_options.type", () -> updatedMappings).get(null).toString().equals("bbq_hnsw")); + client().index( + new IndexRequest("test").source("vector", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray()) + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) + ).get(); + + assertBusy(() -> { + Map updatedMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test") + .get() + .mappings() + .get("test") + .sourceAsMap(); + assertTrue(new WriteField("properties.vector", () -> updatedMappings).exists()); + assertTrue(new WriteField("properties.vector.index_options.type", () -> updatedMappings).get("").toString().equals("bbq_hnsw")); + }); } }