aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-03-01 16:50:06 -0600
committerJP Dillingham <jp@dillingham.me>2026-03-15 11:14:42 -0500
commitd1de2611e3662a318d7f1347996e4cd26ae376a3 (patch)
tree3d87f453f75d858dfa65c24d1e5fc883916736ff
parent6f4c91344d5e4be512dec16600e805cc17178365 (diff)
downloadslskd-d1de2611e3662a318d7f1347996e4cd26ae376a3.tar.gz
add additional tests for exponential comp
-rw-r--r--tests/slskd.Tests.Unit/Common/ComputeTests.cs55
1 files changed, 46 insertions, 9 deletions
diff --git a/tests/slskd.Tests.Unit/Common/ComputeTests.cs b/tests/slskd.Tests.Unit/Common/ComputeTests.cs
index 021d4faa..9090ad36 100644
--- a/tests/slskd.Tests.Unit/Common/ComputeTests.cs
+++ b/tests/slskd.Tests.Unit/Common/ComputeTests.cs
@@ -5,17 +5,54 @@ namespace slskd.Tests.Unit.Common
public class ComputeTests
{
[Theory]
- [InlineData(1, 300000, 0)]
- [InlineData(2, 300000, 1000)]
- [InlineData(3, 300000, 3000)]
- [InlineData(4, 300000, 7000)]
- [InlineData(5, 300000, 15000)]
- [InlineData(6, 300000, 31000)]
- [InlineData(999999, 300000, 300000)]
- public void ExponentialBackoffDelay(int iteration, int maxDelayInMs, int expectedDelay)
+ // base = 1000 (original cases)
+ [InlineData(1, 1000, 300000, 0)]
+ [InlineData(2, 1000, 300000, 1000)]
+ [InlineData(3, 1000, 300000, 3000)]
+ [InlineData(4, 1000, 300000, 7000)]
+ [InlineData(5, 1000, 300000, 15000)]
+ [InlineData(6, 1000, 300000, 31000)]
+ [InlineData(999999, 1000, 300000, 300000)]
+ // base = 500 — delay should be half of base=1000 cases
+ [InlineData(1, 500, 300000, 0)]
+ [InlineData(2, 500, 300000, 500)]
+ [InlineData(3, 500, 300000, 1500)]
+ [InlineData(4, 500, 300000, 3500)]
+ [InlineData(5, 500, 300000, 7500)]
+ [InlineData(6, 500, 300000, 15500)]
+ [InlineData(999999, 500, 300000, 300000)]
+ // base = 2000 — delay should be double of base=1000 cases
+ [InlineData(1, 2000, 300000, 0)]
+ [InlineData(2, 2000, 300000, 2000)]
+ [InlineData(3, 2000, 300000, 6000)]
+ [InlineData(4, 2000, 300000, 14000)]
+ [InlineData(5, 2000, 300000, 30000)]
+ [InlineData(6, 2000, 300000, 62000)]
+ [InlineData(999999, 2000, 300000, 300000)]
+ public void ExponentialBackoffDelay_Returns_Expected_Delay(int iteration, int baseDelayInMilliseconds, int maxDelayInMs, int expectedDelay)
{
- var (computedDelay, _) = Compute.ExponentialBackoffDelay(iteration, maxDelayInMs);
+ var (computedDelay, _) = Compute.ExponentialBackoffDelay(iteration, baseDelayInMilliseconds, maxDelayInMs);
Assert.Equal(expectedDelay, computedDelay);
}
+
+ [Fact]
+ public void ExponentialBackoffDelay_Uses_Default_Base_Delay_Of_1000()
+ {
+ var (withDefault, _) = Compute.ExponentialBackoffDelay(iteration: 3);
+ var (withExplicit, _) = Compute.ExponentialBackoffDelay(iteration: 3, baseDelayInMilliseconds: 1000);
+
+ Assert.Equal(withExplicit, withDefault);
+ }
+
+ [Theory]
+ [InlineData(1000)]
+ [InlineData(500)]
+ [InlineData(2000)]
+ public void ExponentialBackoffDelay_Returns_Jitter_Within_Base_Delay(int baseDelayInMilliseconds)
+ {
+ var (_, jitter) = Compute.ExponentialBackoffDelay(5, baseDelayInMilliseconds, int.MaxValue);
+
+ Assert.InRange(jitter, 0, baseDelayInMilliseconds - 1);
+ }
}
}