@Test
@Timeout(value = 1, unit = TimeUnit.SECONDS)
public void testScheduleException() throws InterruptedException {

    Semaphore s = new Semaphore(0);
    TestSchedulerTemporalAdjuster temporalAdjuster = new TestSchedulerTemporalAdjuster();
    SchedulerRunnable runnable = () -> {
        // Pass a exception not very likely thrown by the scheduler it self to avoid missing real exceptions.
        throw new FileNotFoundException("testBeforeTimeoutException");
    };
    ScheduledCompletableFuture<Void> schedule = scheduler.schedule(runnable, temporalAdjuster);
    schedule.getPromise().exceptionally(e -> {
        if (e instanceof FileNotFoundException) {
            s.release();
        }
        return null;
    });
    s.acquire(1);
    Thread.sleep(300); // wait a little longer to see if not more are scheduled.
    assertEquals(0, s.availablePermits(), "Scheduler should not have released more after cancel");
    assertEquals(0, temporalAdjuster.getCount(), "Scheduler should have run 0 time");
}