Skip to content

Commit 0bbea60

Browse files
authored
Fix flaky testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled (#20640)
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 <andrross@amazon.com>
1 parent 6760346 commit 0bbea60

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.opensearch.common.settings.Settings;
4848
import org.opensearch.common.settings.SettingsException;
4949
import org.opensearch.common.unit.TimeValue;
50+
import org.opensearch.common.util.FeatureFlags;
5051
import org.opensearch.common.util.concurrent.ThreadContext;
5152
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
5253
import org.opensearch.common.xcontent.XContentFactory;
@@ -797,42 +798,45 @@ public void onFailure(Exception e) {
797798
}
798799

799800
public void testPutGlobalV2TemplateWhichProvidesContextWithContextDisabled() throws Exception {
800-
MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
801-
ComposableIndexTemplate globalIndexTemplate = new ComposableIndexTemplate(
802-
List.of("*"),
803-
null,
804-
List.of(),
805-
null,
806-
null,
807-
null,
808-
null,
809-
new Context("any")
810-
);
811-
InvalidIndexTemplateException ex = expectThrows(
812-
InvalidIndexTemplateException.class,
813-
() -> metadataIndexTemplateService.putIndexTemplateV2(
814-
"testing",
815-
true,
816-
"template-referencing-context-as-ct",
817-
TimeValue.timeValueSeconds(30L),
818-
globalIndexTemplate,
819-
new ActionListener<AcknowledgedResponse>() {
820-
@Override
821-
public void onResponse(AcknowledgedResponse response) {
822-
fail("the listener should not be invoked as validation should fail");
823-
}
824-
825-
@Override
826-
public void onFailure(Exception e) {
827-
fail("the listener should not be invoked as validation should fail");
801+
// Explicitly disable the FF
802+
FeatureFlags.TestUtils.with(APPLICATION_BASED_CONFIGURATION_TEMPLATES, false, () -> {
803+
MetadataIndexTemplateService metadataIndexTemplateService = getMetadataIndexTemplateService();
804+
ComposableIndexTemplate globalIndexTemplate = new ComposableIndexTemplate(
805+
List.of("*"),
806+
null,
807+
List.of(),
808+
null,
809+
null,
810+
null,
811+
null,
812+
new Context("any")
813+
);
814+
InvalidIndexTemplateException ex = expectThrows(
815+
InvalidIndexTemplateException.class,
816+
() -> metadataIndexTemplateService.putIndexTemplateV2(
817+
"testing",
818+
true,
819+
"template-referencing-context-as-ct",
820+
TimeValue.timeValueSeconds(30L),
821+
globalIndexTemplate,
822+
new ActionListener<AcknowledgedResponse>() {
823+
@Override
824+
public void onResponse(AcknowledgedResponse response) {
825+
fail("the listener should not be invoked as validation should fail");
826+
}
827+
828+
@Override
829+
public void onFailure(Exception e) {
830+
fail("the listener should not be invoked as validation should fail");
831+
}
828832
}
829-
}
830-
)
831-
);
832-
assertTrue(
833-
"Invalid exception message." + ex.getMessage(),
834-
ex.getMessage().contains("specifies a context which cannot be used without enabling")
835-
);
833+
)
834+
);
835+
assertTrue(
836+
"Invalid exception message." + ex.getMessage(),
837+
ex.getMessage().contains("specifies a context which cannot be used without enabling")
838+
);
839+
});
836840
}
837841

838842
@LockFeatureFlag(APPLICATION_BASED_CONFIGURATION_TEMPLATES)

0 commit comments

Comments
 (0)