From c24885decaf7dd2198d5a483c8494ad4000589ed Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 13 May 2020 23:51:31 -0400 Subject: [PATCH] Reduce test load in TaskManagerTests --- .../java/org/elasticsearch/tasks/TaskManagerTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java b/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java index 8d4d9f946f182..b2254e22f8eaf 100644 --- a/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java +++ b/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Phaser; +import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; @@ -115,7 +116,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF expectedCancelledTasks.add(task); } } - assertBusy(() -> assertThat(cancelledTasks, equalTo(expectedCancelledTasks))); + assertBusy(() -> assertThat(cancelledTasks, equalTo(expectedCancelledTasks)), 30, TimeUnit.SECONDS); for (FakeTcpChannel channel : channels) { channel.close(); } @@ -132,7 +133,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF } }); Set expectedCancelledTasks = ConcurrentCollections.newConcurrentSet(); - FakeTcpChannel[] channels = new FakeTcpChannel[randomIntBetween(2, 20)]; + FakeTcpChannel[] channels = new FakeTcpChannel[randomIntBetween(1, 10)]; for (int i = 0; i < channels.length; i++) { channels[i] = new FakeTcpChannel(); } @@ -142,7 +143,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF String threadName = "thread-" + t; threads[t] = new Thread(() -> { phaser.arriveAndAwaitAdvance(); - int iterations = randomIntBetween(100, 1000); + int iterations = randomIntBetween(50, 500); for (int i = 0; i < iterations; i++) { final FakeTcpChannel channel = randomFrom(channels); final Task task = taskManager.register("transport", "test", new CancellableRequest(threadName + ":" + i)); @@ -161,7 +162,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF for (Thread thread : threads) { thread.join(); } - assertBusy(() -> assertThat(cancelledTasks, equalTo(expectedCancelledTasks))); + assertBusy(() -> assertThat(cancelledTasks, equalTo(expectedCancelledTasks)), 1, TimeUnit.MINUTES); assertThat(taskManager.numberOfChannelPendingTaskTrackers(), equalTo(0)); }