@Test
void unavailable() {

    final Instant now = Instant.now();
    setClock(Clock.fixed(now, Defaults.ZONE_ID));
    final Runnable r = mock(Runnable.class);
    doThrow(new ClientErrorException(Response.Status.TOO_MANY_REQUESTS)).when(r)
        .run();
    final PowerTenant t = new TenantBuilder()
        .withApi(new ApiProvider(null))
        .withSecrets(SecretProvider.inMemory("someone@somewhere.cz"))
        .build(false);
    final Skippable s = new Skippable(r, t);
    logger.debug("First run.");
    s.run();
    verify(r, times(1)).run();
    assertThat(t.getAvailability()
        .isAvailable()).isFalse();
    // move one second, make sure it checks again
    final int mandatoryDelay = 60;
    setClock(Clock.fixed(now.plus(Duration.ofSeconds(mandatoryDelay + 1)), Defaults.ZONE_ID));
    logger.debug("Second run.");
    doThrow(ServerErrorException.class).when(r)
        .run();
    s.run();
    verify(r, times(2)).run();
    assertThat(t.getAvailability()
        .isAvailable()).isFalse();
    // but it failed again, exponential backoff in effect
    setClock(Clock.fixed(now.plus(Duration.ofSeconds(mandatoryDelay + 2)), Defaults.ZONE_ID));
    logger.debug("Third run.");
    doThrow(ResponseProcessingException.class).when(r)
        .run();
    s.run();
    verify(r, times(3)).run();
    assertThat(t.getAvailability()
        .isAvailable()).isFalse();
    setClock(Clock.fixed(now.plus(Duration.ofSeconds(mandatoryDelay + 3)), Defaults.ZONE_ID));
    logger.debug("Fourth run.");
    doNothing().when(r)
        .run();
    s.run();
    verify(r, times(3)).run(); // not run as we're in the exponential backoff
    assertThat(t.getAvailability()
        .isAvailable()).isFalse();
    setClock(Clock.fixed(now.plus(Duration.ofSeconds(mandatoryDelay + 4)), Defaults.ZONE_ID));
    logger.debug("Fourth run.");
    s.run();
    verify(r, times(4)).run(); // it was run now
    assertThat(t.getAvailability()
        .isAvailable()).isTrue();
}