From 32d6d4a5578f2d6b85834423adad576bda6b4d3d Mon Sep 17 00:00:00 2001 From: Pooya Salehi Date: Thu, 28 Jul 2022 09:31:17 +0200 Subject: [PATCH] Log more details in TaskAssertions (#88864) --- .../http/IndicesSegmentsRestCancellationIT.java | 2 ++ .../java/org/elasticsearch/test/TaskAssertions.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/IndicesSegmentsRestCancellationIT.java b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/IndicesSegmentsRestCancellationIT.java index d2ab3b5a01636..e8b36025a762a 100644 --- a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/IndicesSegmentsRestCancellationIT.java +++ b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/IndicesSegmentsRestCancellationIT.java @@ -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); diff --git a/test/framework/src/main/java/org/elasticsearch/test/TaskAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/TaskAssertions.java index 80361194c4580..7ffe1afdcfdb1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TaskAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TaskAssertions.java @@ -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; @@ -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 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; } } @@ -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",