From de0867ad02a68efb41645f3f8657c59c9a105dc8 Mon Sep 17 00:00:00 2001 From: Andrew Ross Date: Mon, 16 Feb 2026 16:09:09 -0800 Subject: [PATCH] Fix flaky testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled Somehow the feature flag was getting enabled while this test expects it to be disabled. This change ensures the flag will be disabled for this test case. Signed-off-by: Andrew Ross --- .../MetadataIndexTemplateServiceTests.java | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java index e1a7257074ad5..c66f289bc8acf 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java @@ -47,6 +47,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.SettingsException; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; @@ -797,42 +798,45 @@ public void onFailure(Exception e) { } public void testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled() throws Exception { - MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService(); - ComposableIndexTemplate globalIndexTemplate = new ComposableIndexTemplate( - List.of("*"), - null, - List.of(), - null, - null, - null, - null, - new Context("any") - ); - InvalidIndexTemplateException ex = expectThrows( - InvalidIndexTemplateException.class, - () -> metadataIndexTemplateService.putIndexTemplateV2( - "testing", - true, - "template-referencing-context-as-ct", - TimeValue.timeValueSeconds(30L), - globalIndexTemplate, - new ActionListener() { - @Override - public void onResponse(AcknowledgedResponse response) { - fail("the listener should not be invoked as validation should fail"); - } - - @Override - public void onFailure(Exception e) { - fail("the listener should not be invoked as validation should fail"); + // Explicitly disable the FF + FeatureFlags.TestUtils.with(APPLICATION_BASED_CONFIGURATION_TEMPLATES, false, () -> { + MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService(); + ComposableIndexTemplate globalIndexTemplate = new ComposableIndexTemplate( + List.of("*"), + null, + List.of(), + null, + null, + null, + null, + new Context("any") + ); + InvalidIndexTemplateException ex = expectThrows( + InvalidIndexTemplateException.class, + () -> metadataIndexTemplateService.putIndexTemplateV2( + "testing", + true, + "template-referencing-context-as-ct", + TimeValue.timeValueSeconds(30L), + globalIndexTemplate, + new ActionListener() { + @Override + public void onResponse(AcknowledgedResponse response) { + fail("the listener should not be invoked as validation should fail"); + } + + @Override + public void onFailure(Exception e) { + fail("the listener should not be invoked as validation should fail"); + } } - } - ) - ); - assertTrue( - "Invalid exception message." + ex.getMessage(), - ex.getMessage().contains("specifies a context which cannot be used without enabling") - ); + ) + ); + assertTrue( + "Invalid exception message." + ex.getMessage(), + ex.getMessage().contains("specifies a context which cannot be used without enabling") + ); + }); } @LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)