فهرست منبع

[ML] Fix license feature test cleanup (#84020)

Testing license features for can cause the .ml-stats index to be created
some time after the tests complete. This can cause the post-test cleanup
to fail.

This change fixes the problem by waiting for pending tasks in the first
stage cleanup, before the main cleanup methods run in the base classes.

Fixes #83923
David Roberts 3 سال پیش
والد
کامیت
15e522ec41

+ 6 - 2
x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureLicenseTrackingIT.java

@@ -31,6 +31,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Job;
 import org.elasticsearch.xpack.core.ml.job.config.JobState;
 import org.elasticsearch.xpack.ml.MachineLearning;
 import org.elasticsearch.xpack.ml.MlSingleNodeTestCase;
+import org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase;
 import org.junit.After;
 
 import java.time.ZonedDateTime;
@@ -57,7 +58,7 @@ public class TestFeatureLicenseTrackingIT extends MlSingleNodeTestCase {
     private final Set<String> createdPipelines = new HashSet<>();
 
     @After
-    public void cleanup() {
+    public void cleanup() throws Exception {
         for (String pipeline : createdPipelines) {
             try {
                 client().execute(DeletePipelineAction.INSTANCE, new DeletePipelineRequest(pipeline)).actionGet();
@@ -65,6 +66,9 @@ public class TestFeatureLicenseTrackingIT extends MlSingleNodeTestCase {
                 logger.warn(() -> new ParameterizedMessage("error cleaning up pipeline [{}]", pipeline), ex);
             }
         }
+        // Some of the tests have async side effects. We need to wait for these to complete before continuing
+        // the cleanup, otherwise unexpected indices may get created during the cleanup process.
+        BaseMlIntegTestCase.waitForPendingTasks(client());
     }
 
     public void testFeatureTrackingAnomalyJob() throws Exception {
@@ -125,7 +129,7 @@ public class TestFeatureLicenseTrackingIT extends MlSingleNodeTestCase {
             .setInferenceConfig(new ClassificationConfig(3))
             .setParsedDefinition(
                 new TrainedModelDefinition.Builder().setPreProcessors(
-                    Arrays.asList(new OneHotEncoding("other.categorical", oneHotEncoding, false))
+                    List.of(new OneHotEncoding("other.categorical", oneHotEncoding, false))
                 ).setTrainedModel(buildClassification(true))
             )
             .build();