Skip to content

Commit

Permalink
Merge pull request #381 from camunda-community-hub/zell-fix-380
Browse files Browse the repository at this point in the history
Return max if exceeding max wait time
  • Loading branch information
ChrisKujawa authored Feb 7, 2022
2 parents 358c012 + de7fbbf commit 50cb6e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Client.UnitTests/ZeebeClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 3 additions & 3 deletions Client/ZeebeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace Zeebe.Client
/// <inheritdoc />
public class ZeebeClient : IZeebeClient
{
private static readonly int MaxWaitTimeInSeconds = 60;
private static readonly Func<int, TimeSpan> DefaultWaitTimeProvider =
retryAttempt => TimeSpan.FromSeconds(Math.Max(Math.Pow(2, retryAttempt), MaxWaitTimeInSeconds));
internal static readonly int MaxWaitTimeInSeconds = 60;
internal static readonly Func<int, TimeSpan> DefaultWaitTimeProvider =
retryAttempt => TimeSpan.FromSeconds(Math.Min(Math.Pow(2, retryAttempt), MaxWaitTimeInSeconds));
private static readonly TimeSpan DefaultKeepAlive = TimeSpan.FromSeconds(30);

private readonly Channel channelToGateway;
Expand Down

0 comments on commit 50cb6e9

Please sign in to comment.