Skip to content

Commit c1f0b3d

Browse files
committed
Rework executor shutdown method
1 parent 9cddba5 commit c1f0b3d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/src/test/java/org/elasticsearch/common/util/concurrent/TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutorTests.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.test.ESTestCase;
1414

15+
import java.util.concurrent.Executors;
1516
import java.util.concurrent.TimeUnit;
1617

1718
import static org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig.DEFAULT_EWMA_ALPHA;
@@ -48,8 +49,7 @@ public void testExecutionPerIndexStatistics() throws Exception {
4849
assertTrue(executor.getSearchLoadPerIndex(INDEX_NAME) > 0);
4950
});
5051

51-
executor.shutdown();
52-
executor.awaitTermination(10, TimeUnit.SECONDS);
52+
shutdownExecutor(executor);
5353
}
5454

5555
/** Execute a blank task {@code times} times for the executor */
@@ -60,4 +60,13 @@ private void executeTask(TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor e
6060
executor.execute(runnable);
6161
}
6262
}
63+
64+
private void shutdownExecutor(EsThreadPoolExecutor executor) {
65+
executor.shutdown();
66+
try {
67+
if (executor.awaitTermination(5, TimeUnit.SECONDS) == false) executor.shutdownNow();
68+
} catch(InterruptedException e) {
69+
executor.shutdownNow();
70+
}
71+
}
6372
}

0 commit comments

Comments
 (0)