Skip to content

Commit

Permalink
Log more details in TaskAssertions (elastic#88864)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxsalehi authored Jul 28, 2022
1 parent 8a159e9 commit 32d6d4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
import org.elasticsearch.client.Request;
import org.elasticsearch.test.junit.annotations.TestLogging;

@TestLogging(value = "org.elasticsearch.tasks.TaskManager:TRACE,org.elasticsearch.test.TaskAssertions:TRACE", reason = "debugging")
public class IndicesSegmentsRestCancellationIT extends BlockedSearcherRestCancellationTestCase {
public void testIndicesSegmentsRestCancellation() throws Exception {
runTest(new Request(HttpGet.METHOD_NAME, "/_segments"), IndicesSegmentsAction.NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskInfo;
import org.elasticsearch.tasks.TaskManager;
import org.elasticsearch.transport.TransportService;

import java.util.List;
import java.util.stream.Collectors;

import static junit.framework.TestCase.assertTrue;
import static junit.framework.TestCase.fail;
Expand All @@ -33,7 +35,14 @@ public static void awaitTaskWithPrefix(String actionPrefix) throws Exception {

assertBusy(() -> {
for (TransportService transportService : internalCluster().getInstances(TransportService.class)) {
if (transportService.getTaskManager().getTasks().values().stream().anyMatch(t -> t.getAction().startsWith(actionPrefix))) {
List<Task> matchingTasks = transportService.getTaskManager()
.getTasks()
.values()
.stream()
.filter(t -> t.getAction().startsWith(actionPrefix))
.collect(Collectors.toList());
if (matchingTasks.isEmpty() == false) {
logger.trace("--> found {} tasks with prefix [{}]: {}", matchingTasks.size(), actionPrefix, matchingTasks);
return;
}
}
Expand All @@ -51,6 +60,7 @@ public static void assertAllCancellableTasksAreCancelled(String actionPrefix) th
assertTrue(taskManager.assertCancellableTaskConsistency());
for (CancellableTask cancellableTask : taskManager.getCancellableTasks().values()) {
if (cancellableTask.getAction().startsWith(actionPrefix)) {
logger.trace("--> found task with prefix [{}] marked as cancelled: [{}]", actionPrefix, cancellableTask);
foundTask = true;
assertTrue(
"task " + cancellableTask.getId() + "/" + cancellableTask.getAction() + " not cancelled",
Expand Down

0 comments on commit 32d6d4a

Please sign in to comment.