The control layer keeps doubling after the first minute up to ten minutes, and the QUIC redial doubles after twelve short attempts up to five minutes, instead of retrying every minute or every five seconds forever.
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
|
|
namespace MoShiro.Agent.Tests;
|
|
|
|
public sealed class ControlBackoffTests
|
|
{
|
|
[Fact]
|
|
public void Next_UsesRequestedEscalationThenKeepsDoublingToTenMinutes()
|
|
{
|
|
var backoff = new ControlBackoff();
|
|
TimeSpan[] expected =
|
|
[
|
|
TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4),
|
|
TimeSpan.FromSeconds(8), TimeSpan.FromSeconds(16),
|
|
TimeSpan.FromSeconds(32), TimeSpan.FromSeconds(32), TimeSpan.FromSeconds(32),
|
|
TimeSpan.FromSeconds(32), TimeSpan.FromSeconds(32),
|
|
TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(2), TimeSpan.FromMinutes(4),
|
|
TimeSpan.FromMinutes(8), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10),
|
|
];
|
|
|
|
Assert.Equal(expected, expected.Select(_ => backoff.Next()));
|
|
}
|
|
|
|
[Fact]
|
|
public void Reset_RestartsAtOneSecond()
|
|
{
|
|
var backoff = new ControlBackoff();
|
|
_ = backoff.Next();
|
|
_ = backoff.Next();
|
|
|
|
backoff.Reset();
|
|
|
|
Assert.Equal(TimeSpan.FromSeconds(1), backoff.Next());
|
|
}
|
|
}
|