Skip to content

Commit 92bccf5

Browse files
authored
Fix ThreadPoolTests#testDetailedUtilizationMetric (#138393) (#138395)
(cherry picked from commit 3749b6e) # Conflicts: # server/src/main/java/org/elasticsearch/common/util/concurrent/TaskExecutionTimeTrackingEsThreadPoolExecutor.java
1 parent cd97b85 commit 92bccf5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,12 @@ public void testDetailedUtilizationMetric() throws Exception {
528528
});
529529
safeAwait(barrier);
530530
safeGet(future);
531-
final long maxDurationNanos = System.nanoTime() - beforeStartNanos;
532-
533531
// Wait for TaskExecutionTimeTrackingEsThreadPoolExecutor#afterExecute to run
534532
assertBusy(() -> assertThat(executor.getTotalTaskExecutionTime(), greaterThan(0L)));
533+
// When you call submit, the TimedRunnable wraps the FutureTask, so safeGet can return before the duration of
534+
// the task is calculated. Waiting for totalTaskExecutionTime to be updated ensures maxDurationNanos is greater
535+
// than the actual duration.
536+
final long maxDurationNanos = System.nanoTime() - beforeStartNanos;
535537

536538
final long beforeMetricsCollectedNanos = System.nanoTime();
537539
meterRegistry.getRecorder().collect();

0 commit comments

Comments
 (0)