@Test
@Timeout(value = 300, unit = TimeUnit.MILLISECONDS)
public void testBeforeTimeoutException() throws Throwable {

    CompletableFuture<Integer> d = new CompletableFuture<>();
    ScheduledCompletableFuture<Integer> before = scheduler.before(d, Duration.ofMillis(100));
    Thread.sleep(200);
    d.complete(3);
    d.get();
    assertTrue(before.isDone(), "Scheduled job should be done");
    assertTrue(before.getPromise().isCompletedExceptionally(),
            "Before CompletableFuture should have completed with an exception");
    assertThrows(TimeoutException.class, () -> {
        try {
            before.get();
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
}