Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for task completion in IndexLifecycleRunnerTests #94901

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.cluster.service.ClusterApplierService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.service.MasterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -228,4 +229,30 @@ public void onTimeout(TimeValue timeout) {
future.get(30L, TimeUnit.SECONDS);
}
}

public static void awaitNoPendingTasks(ClusterService clusterService) {
PlainActionFuture.<Void, RuntimeException>get(
fut -> clusterService.submitUnbatchedStateUpdateTask(
"await-queue-empty",
new ClusterStateUpdateTask(Priority.LANGUID, TimeValue.timeValueSeconds(10)) {
@Override
public ClusterState execute(ClusterState currentState) {
return currentState;
}

@Override
public void onFailure(Exception e) {
fut.onFailure(e);
}

@Override
public void clusterStateProcessed(ClusterState initialState, ClusterState newState) {
fut.onResponse(null);
}
}
),
10,
TimeUnit.SECONDS
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public void testRunStateChangePolicyWithNoNextStep() throws Exception {

assertEquals(before, after);
assertThat(step.getExecuteCount(), equalTo(1L));
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();
}
Expand Down Expand Up @@ -367,6 +368,7 @@ public void testRunStateChangePolicyWithNextStep() throws Exception {
assertThat(newExecutionState.stepTime(), equalTo(stepTime));
assertThat(step.getExecuteCount(), equalTo(1L));
assertThat(nextStep.getExecuteCount(), equalTo(1L));
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();

Expand Down Expand Up @@ -458,6 +460,7 @@ public void doTestRunPolicyWithFailureToReadPolicy(boolean asyncAction, boolean
newExecutionState.stepInfo(),
containsString("{\"type\":\"illegal_argument_exception\",\"reason\":\"fake failure retrieving step\"}")
);
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();
}
Expand Down Expand Up @@ -489,6 +492,7 @@ public void testRunAsyncActionDoesNotRun() {

assertEquals(before, after);
assertThat(step.getExecuteCount(), equalTo(0L));
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();
}
Expand Down Expand Up @@ -547,6 +551,7 @@ public void testRunStateChangePolicyWithAsyncActionNextStep() throws Exception {
assertNotEquals(before, after);
assertThat(step.getExecuteCount(), equalTo(1L));
assertThat(nextStep.getExecuteCount(), equalTo(1L));
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();

Expand Down Expand Up @@ -618,6 +623,7 @@ public void testRunPeriodicStep() throws Exception {
assertEquals(before, after);
assertThat(step.getExecuteCount(), equalTo(1L));
assertThat(nextStep.getExecuteCount(), equalTo(0L));
ClusterServiceUtils.awaitNoPendingTasks(clusterService);
clusterService.close();
threadPool.shutdownNow();
}
Expand Down