diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt index 965af2cc6..c1d368452 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt @@ -14,7 +14,9 @@ import org.opensearch.client.Request import org.opensearch.client.RequestOptions import org.opensearch.client.Response import org.opensearch.client.RestClient +import org.opensearch.common.Strings import org.opensearch.common.settings.Settings +import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN import org.opensearch.rest.RestStatus import java.nio.file.Files import java.nio.file.Path @@ -39,6 +41,20 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { ) } + // Tests on lower resource machines are experiencing flaky failures due to attempting to force a job to + // start before the job scheduler has registered the index operations listener. Initializing the index + // preemptively seems to give the job scheduler time to listen to operations. + @Before + fun initializeManagedIndex() { + if (!indexExists(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX)) { + val request = Request("PUT", "/${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}") + var entity = "{\"settings\": " + Strings.toString(Settings.builder().put(INDEX_HIDDEN, true).build()) + entity += ",\"mappings\" : ${IndexManagementIndices.indexManagementMappings}}" + request.setJsonEntity(entity) + client().performRequest(request) + } + } + protected val isDebuggingTest = DisableOnDebug(null).isDebugging protected val isDebuggingRemoteCluster = System.getProperty("cluster.debug", "false")!!.toBoolean() protected val isMultiNode = System.getProperty("cluster.number_of_nodes", "1").toInt() > 1