Skip to content

Commit

Permalink
Merge pull request #23580 from njr-11/23579-unexpected-delay
Browse files Browse the repository at this point in the history
test of unit conversions did not allow for rounding up
  • Loading branch information
tevans78 committed Dec 5, 2022
2 parents 9249ef7 + e2d6719 commit 8aadb51
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9389,27 +9389,27 @@ public void testUnitConversions() throws Exception {
ScheduledFuture<?> future1 = schedxsvcDefault.schedule((Runnable) new CounterTask(), 1000000, TimeUnit.DAYS);
try {
long days = future1.getDelay(TimeUnit.DAYS);
if (days != 106751l) // maximum possible due to limiations of java.util.concurrent.TimeUnit
if (days > 1000000l || days < 106751l) // maximum possible due to limitations of java.util.concurrent.TimeUnit
throw new Exception("Task1: Unexpected delay in days: " + days);

long hours = future1.getDelay(TimeUnit.HOURS);
if (hours != 2562047l)
if (hours > 24000000l || hours < 2562047l)
throw new Exception("Task1: Unexpected delay in hours: " + hours);

long minutes = future1.getDelay(TimeUnit.MINUTES);
if (minutes != 153722867l)
if (minutes > 1440000000l || minutes < 153722867l)
throw new Exception("Task1: Unexpected delay in minutes: " + minutes);

long seconds = future1.getDelay(TimeUnit.SECONDS); // expecting 9223372036, but allow for additional time that might have elapsed
if (seconds < 9223372030l || seconds > 9223372036l)
if (seconds > 86400000000l || seconds < 9223372030l)
throw new Exception("Task1: Unexpected delay in seconds: " + seconds);

long millis = future1.getDelay(TimeUnit.MILLISECONDS);
if (millis < 9223372030000l || millis > 9223372038000l)
if (millis > 86400000000000l || millis < 9223372030000l)
throw new Exception("Task1: Unexpected delay in milliseconds: " + millis);

long micros = future1.getDelay(TimeUnit.MICROSECONDS);
if (micros < 9223372030000000l || micros > 9223372038000000l)
if (micros > 86400000000000000l || micros < 9223372030000000l)
throw new Exception("Task1: Unexpected delay in microseconds: " + micros);

long nanos = future1.getDelay(TimeUnit.NANOSECONDS);
Expand All @@ -9424,15 +9424,15 @@ public void testUnitConversions() throws Exception {
throw new Exception("Task2: Unexpected delay in seconds: " + days);

minutes = future2.getDelay(TimeUnit.MINUTES);
if (minutes != 153722866l)
if (minutes > 153722867l || minutes < 153722866l) // allow for rounding up or down
throw new Exception("Task2: Unexpected delay in minutes: " + minutes);

hours = future2.getDelay(TimeUnit.HOURS);
if (hours != 2562047l)
if (hours > 2562048l || hours < 2562047l)
throw new Exception("Task2: Unexpected delay in hours: " + hours);

days = future1.getDelay(TimeUnit.DAYS);
if (days != 106751l)
if (days > 106752l || days < 106751l)
throw new Exception("Task1: Unexpected delay in days: " + days);

int result = future1.compareTo(future2);
Expand All @@ -9446,7 +9446,7 @@ public void testUnitConversions() throws Exception {
}

long days = future1.getDelay(TimeUnit.DAYS);
if (days != 106751l)
if (days > 106752l || days < 106751l)
throw new Exception("Delay should remain unchanged after canceling task in order to be consistent with java.util.concurrent.ScheduledThreadPoolExecutor. Instead: "
+ days);

Expand Down

0 comments on commit 8aadb51

Please sign in to comment.