GJL commented on a change in pull request #9268: [FLINK-13452] Ensure to fail
global when exception happens during reseting tasks of regions
URL: https://github.com/apache/flink/pull/9268#discussion_r310607451
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/concurrent/FutureUtilsTest.java
##########
@@ -235,6 +237,57 @@ public void testRetryWithDelayCancellation() {
assertTrue(scheduledFuture.isCancelled());
}
+ /**
+ * Tests that the operation could be scheduled with expected delay.
+ */
+ @Test
+ public void testScheduleAsyncDelay() throws Exception {
+ final Time delay = Time.milliseconds(500L);
+ final long start = System.currentTimeMillis();
+ final AtomicInteger updateValue = new AtomicInteger(0);
+
+ CompletableFuture<Integer> scheduleAsyncFuture =
FutureUtils.scheduleAsync(
+ () ->
updateValue.addAndGet(ThreadLocalRandom.current().nextInt(100)),
+ delay,
+ TestingUtils.defaultScheduledExecutor());
+
+ int result = scheduleAsyncFuture.get();
+ long completionTime = System.currentTimeMillis() - start;
Review comment:
There some issues that I see here:
1. `System.currentTimeMillis()` is [impacted by system clock
changes](https://stackoverflow.com/a/15620527) – this may cuase test failures
in conjunction with NTP. Therefore `System.nanoTime()` should be preferred.
1. Test will run at least 500ms which is on the slow side for unit tests. I
think it's enough to use `ManuallyTriggeredScheduledExecutor` and see if the
correct result is produced.
1. I don't think using `AtomicInteger` adds test coverage. Imo it's enough
to assert on the value of `result`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services