From 39a2dec558003dcb3dea268d55fc9cc93d08695c Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Thu, 14 May 2020 11:45:36 +0200 Subject: [PATCH] Stop/Start async search maintenance service in tests(#56673) This change ensures that the maintenance service that is responsible for deleting the expired response is stopped between each test. This is needed since we check that no search context are in-flight after each test method. Fixes #55988 --- .../search/AsyncSearchIntegTestCase.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIntegTestCase.java b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIntegTestCase.java index f579b834b723e..1b215068faa09 100644 --- a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIntegTestCase.java +++ b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIntegTestCase.java @@ -12,7 +12,10 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.cluster.ClusterChangedEvent; +import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ContextParser; @@ -34,6 +37,7 @@ import org.elasticsearch.xpack.core.search.action.SubmitAsyncSearchRequest; import org.elasticsearch.xpack.ilm.IndexLifecycle; import org.junit.After; +import org.junit.Before; import java.io.Closeable; import java.util.Arrays; @@ -71,6 +75,25 @@ public List getAggregations() { } } + @Before + public void startMaintenanceService() { + for (AsyncSearchMaintenanceService service : internalCluster().getDataNodeInstances(AsyncSearchMaintenanceService.class)) { + if (service.lifecycleState() == Lifecycle.State.STOPPED) { + // force the service to start again + service.start(); + ClusterState state = internalCluster().clusterService().state(); + service.clusterChanged(new ClusterChangedEvent("noop", state, state)); + } + } + } + + @After + public void stopMaintenanceService() { + for (AsyncSearchMaintenanceService service : internalCluster().getDataNodeInstances(AsyncSearchMaintenanceService.class)) { + service.stop(); + } + } + @After public void releaseQueryLatch() { BlockingQueryBuilder.releaseQueryLatch();