Skip to content

Commit

Permalink
Fix PersistentTasksClusterServiceTests (#92002)
Browse files Browse the repository at this point in the history
Today these tests don't wait for the assertions to run before shutting
down the master service, and today if the master service shuts down then
work (such as these assertions) is silently dropped. This commit ensures
that the assertions have run before the test completes.
  • Loading branch information
DaveCTurner authored Nov 29, 2022
1 parent 2b268d3 commit d3fbb3e
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -527,7 +528,7 @@ public void testPeriodicRecheckOffMaster() {
assertFalse(service.getPeriodicRechecker().isScheduled());
}

public void testUnassignTask() {
public void testUnassignTask() throws InterruptedException {
ClusterState clusterState = initialState();
ClusterState.Builder builder = ClusterState.builder(clusterState);
PersistentTasksCustomMetadata.Builder tasks = PersistentTasksCustomMetadata.builder(
Expand All @@ -545,14 +546,18 @@ public void testUnassignTask() {
clusterState = builder.metadata(metadata).nodes(nodes).build();
setState(clusterService, clusterState);
PersistentTasksClusterService service = createService((params, candidateNodes, currentState) -> new Assignment("_node_2", "test"));
final var countDownLatch = new CountDownLatch(1);
service.unassignPersistentTask(unassignedId, tasks.getLastAllocationId(), "unassignment test", ActionListener.wrap(task -> {
assertThat(task.getAssignment().getExecutorNode(), is(nullValue()));
assertThat(task.getId(), equalTo(unassignedId));
assertThat(task.getAssignment().getExplanation(), equalTo("unassignment test"));
countDownLatch.countDown();
}, e -> fail()));

assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));
}

public void testUnassignNonExistentTask() {
public void testUnassignNonExistentTask() throws InterruptedException {
ClusterState clusterState = initialState();
ClusterState.Builder builder = ClusterState.builder(clusterState);
PersistentTasksCustomMetadata.Builder tasks = PersistentTasksCustomMetadata.builder(
Expand All @@ -568,12 +573,18 @@ public void testUnassignNonExistentTask() {
clusterState = builder.metadata(metadata).nodes(nodes).build();
setState(clusterService, clusterState);
PersistentTasksClusterService service = createService((params, candidateNodes, currentState) -> new Assignment("_node_2", "test"));
final var countDownLatch = new CountDownLatch(1);
service.unassignPersistentTask(
"missing-task",
tasks.getLastAllocationId(),
"unassignment test",
ActionListener.wrap(task -> fail(), e -> assertThat(e, instanceOf(ResourceNotFoundException.class)))
ActionListener.wrap(task -> fail(), e -> {
assertThat(e, instanceOf(ResourceNotFoundException.class));
countDownLatch.countDown();
})
);

assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));
}

public void testTasksNotAssignedToShuttingDownNodes() {
Expand Down

0 comments on commit d3fbb3e

Please sign in to comment.