Skip to content

Commit 51191eb

Browse files
committed
Improve documentation of test
1 parent 876ae78 commit 51191eb

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,40 @@ public void testQueueLatencyMetrics() {
177177
try {
178178
final var barrier = new CyclicBarrier(2);
179179
final ExponentialBucketHistogram expectedHistogram = new ExponentialBucketHistogram();
180+
181+
/*
182+
* The thread pool has a single thread, so we submit a task that will occupy that thread
183+
* and cause subsequent tasks to be queued
184+
*/
180185
Future<?> runningTask = executor.submit(() -> {
181186
safeAwait(barrier);
182187
safeAwait(barrier);
183188
});
184-
safeAwait(barrier); // wait till first task starts
185-
expectedHistogram.addObservation(0L); // first task should not be delayed
189+
safeAwait(barrier); // wait till the first task starts
190+
expectedHistogram.addObservation(0L); // the first task should not be delayed
191+
192+
/*
193+
* On each iteration we submit a task - which will be queued because of the
194+
* currently running task, pause for some random interval, then unblock the
195+
* new task by releasing the currently running task. This gives us a lower
196+
* bound for the real delays (the real delays will be greater than or equal
197+
* to the synthetic delays we add, i.e. each percentile should be >= our
198+
* expected values)
199+
*/
186200
for (int i = 0; i < 10; i++) {
187201
Future<?> waitingTask = executor.submit(() -> {
188202
safeAwait(barrier);
189203
safeAwait(barrier);
190204
});
191205
final long delayTimeMs = randomLongBetween(1, 50);
192206
safeSleep(delayTimeMs);
193-
safeAwait(barrier); // let running task complete
194-
safeAwait(barrier); // wait for next task to start
207+
safeAwait(barrier); // let the running task complete
208+
safeAwait(barrier); // wait for the next task to start
195209
safeGet(runningTask); // ensure previous task is complete
196210
expectedHistogram.addObservation(delayTimeMs);
197211
runningTask = waitingTask;
198212
}
199-
safeAwait(barrier); // let last task finish
213+
safeAwait(barrier); // let the last task finish
200214
safeGet(runningTask);
201215
meterRegistry.getRecorder().collect();
202216

0 commit comments

Comments
 (0)