Skip to content

Commit

Permalink
[ML] Fix license feature test cleanup (elastic#84020)
Browse files Browse the repository at this point in the history
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 elastic#83923
  • Loading branch information
droberts195 committed Feb 16, 2022
1 parent 6432201 commit ee4fef7
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand All @@ -57,14 +58,17 @@ 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();
} catch (Exception ex) {
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 {
Expand Down Expand Up @@ -125,7 +129,7 @@ public void testFeatureTrackingInferenceModelPipeline() throws Exception {
.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();
Expand Down

0 comments on commit ee4fef7

Please sign in to comment.