using Tiku.Api.Background;

namespace Tiku.IntegrationTests.Api;

public sealed class DevelopmentTenantDomainLifecycleHostedServiceTests
{
    [Theory]
    [InlineData(0, 2)]
    [InlineData(1, 2)]
    [InlineData(2, 4)]
    [InlineData(3, 8)]
    [InlineData(8, 256)]
    [InlineData(9, 300)]
    [InlineData(100, 300)]
    public void Idle_polling_backs_off_exponentially_and_is_capped(int idleIterations, int expectedSeconds)
    {
        var delay = DevelopmentTenantDomainLifecycleHostedService.CalculateDelay(
            TimeSpan.FromSeconds(2),
            TimeSpan.FromSeconds(300),
            idleIterations);

        Assert.Equal(TimeSpan.FromSeconds(expectedSeconds), delay);
    }
}
