Skip to content

Commit

Permalink
Stop/Start async search maintenance service in tests(#56673)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jimczi authored May 14, 2020
1 parent cbb8b17 commit 39a2dec
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -71,6 +75,25 @@ public List<AggregationSpec> 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();
Expand Down

0 comments on commit 39a2dec

Please sign in to comment.