From 2039cc813be0864ea748f64202841133058fdbc3 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 7 Jan 2020 09:02:35 +0000 Subject: [PATCH] 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 --- .../coordination/DeterministicTaskQueueTests.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/framework/src/test/java/org/elasticsearch/cluster/coordination/DeterministicTaskQueueTests.java b/test/framework/src/test/java/org/elasticsearch/cluster/coordination/DeterministicTaskQueueTests.java index 129ef89e88c..b7fbde22f50 100644 --- a/test/framework/src/test/java/org/elasticsearch/cluster/coordination/DeterministicTaskQueueTests.java +++ b/test/framework/src/test/java/org/elasticsearch/cluster/coordination/DeterministicTaskQueueTests.java @@ -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() {