From 54f664a6e04454ba85a0aac39328c95f9181ea56 Mon Sep 17 00:00:00 2001 From: Christopher Zell Date: Mon, 7 Feb 2022 21:22:15 +0100 Subject: [PATCH 1/2] test: add regresion test --- Client.UnitTests/ZeebeClientTest.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Client.UnitTests/ZeebeClientTest.cs b/Client.UnitTests/ZeebeClientTest.cs index e7262fde..1c798c7b 100644 --- a/Client.UnitTests/ZeebeClientTest.cs +++ b/Client.UnitTests/ZeebeClientTest.cs @@ -245,6 +245,33 @@ public async Task ShouldUseAccessTokenSupplier() Assert.AreEqual(3, accessTokenSupplier.Count); } + [Test] + public void ShouldCalculateNextGreaterWaitTime() + { + // given + var defaultWaitTimeProvider = ZeebeClient.DefaultWaitTimeProvider; + + // when + var firstSpan = defaultWaitTimeProvider.Invoke(1); + var secondSpan = defaultWaitTimeProvider.Invoke(2); + + // then + Assert.Greater(secondSpan, firstSpan); + } + + [Test] + public void ShouldReturnMaxIfReachingMaxWaitTime() + { + // given + var defaultWaitTimeProvider = ZeebeClient.DefaultWaitTimeProvider; + + // when + var maxTime = defaultWaitTimeProvider.Invoke(100); + + // then + Assert.AreEqual(TimeSpan.FromSeconds(ZeebeClient.MaxWaitTimeInSeconds), maxTime); + } + private class SimpleAccessTokenSupplier : IAccessTokenSupplier { public int Count { get; private set; } From de7fbbf092916328e5198bd0fd4b4e9e4393ef8d Mon Sep 17 00:00:00 2001 From: Christopher Zell Date: Mon, 7 Feb 2022 21:22:38 +0100 Subject: [PATCH 2/2] fix: return max if exceeding max wait time --- Client/ZeebeClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/ZeebeClient.cs b/Client/ZeebeClient.cs index 7a3e157d..f4816d7f 100644 --- a/Client/ZeebeClient.cs +++ b/Client/ZeebeClient.cs @@ -33,9 +33,9 @@ namespace Zeebe.Client /// public class ZeebeClient : IZeebeClient { - private static readonly int MaxWaitTimeInSeconds = 60; - private static readonly Func DefaultWaitTimeProvider = - retryAttempt => TimeSpan.FromSeconds(Math.Max(Math.Pow(2, retryAttempt), MaxWaitTimeInSeconds)); + internal static readonly int MaxWaitTimeInSeconds = 60; + internal static readonly Func DefaultWaitTimeProvider = + retryAttempt => TimeSpan.FromSeconds(Math.Min(Math.Pow(2, retryAttempt), MaxWaitTimeInSeconds)); private static readonly TimeSpan DefaultKeepAlive = TimeSpan.FromSeconds(30); private readonly Channel channelToGateway;