Fix testDelayVariabilityAppliesToFutureTasks (#50667)
This test seems to be bogus as it was confusing a nominal execution time with a delay (i.e. an elapsed time). This commit reworks the test to address this. Fixes #50650
This commit is contained in:
parent
a3ab7eb95d
commit
2039cc813b
|
@ -376,20 +376,19 @@ public class DeterministicTaskQueueTests extends ESTestCase {
|
|||
public void testDelayVariabilityAppliesToFutureTasks() {
|
||||
final DeterministicTaskQueue deterministicTaskQueue = newTaskQueue();
|
||||
advanceToRandomTime(deterministicTaskQueue);
|
||||
final long delayMillis = randomLongBetween(30000, 60000);
|
||||
final long variabilityMillis = randomLongBetween(100, 500);
|
||||
final long nominalExecutionTime = randomLongBetween(0, 60000);
|
||||
final long variabilityMillis = randomLongBetween(1, 500);
|
||||
final long startTime = deterministicTaskQueue.getCurrentTimeMillis();
|
||||
deterministicTaskQueue.setExecutionDelayVariabilityMillis(variabilityMillis);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
deterministicTaskQueue.scheduleAt(delayMillis, () -> {});
|
||||
deterministicTaskQueue.scheduleAt(nominalExecutionTime, () -> {});
|
||||
}
|
||||
final long expectedEndTime = deterministicTaskQueue.getLatestDeferredExecutionTime();
|
||||
assertThat(expectedEndTime, greaterThan(nominalExecutionTime)); // fails if every task has zero variability -- vanishingly unlikely
|
||||
assertThat(expectedEndTime, lessThanOrEqualTo(Math.max(startTime, nominalExecutionTime + variabilityMillis)));
|
||||
|
||||
final long startTime = deterministicTaskQueue.getCurrentTimeMillis();
|
||||
deterministicTaskQueue.runAllTasks();
|
||||
final long elapsedTime = deterministicTaskQueue.getCurrentTimeMillis() - startTime;
|
||||
assertThat(deterministicTaskQueue.getCurrentTimeMillis(), is(expectedEndTime));
|
||||
assertThat(elapsedTime, greaterThan(delayMillis)); // fails with negligible probability
|
||||
assertThat(elapsedTime, lessThanOrEqualTo(delayMillis + variabilityMillis));
|
||||
}
|
||||
|
||||
public void testThreadPoolSchedulesPeriodicFutureTasks() {
|
||||
|
|
Loading…
Reference in New Issue