public void CalculateRetryDelayUsesExponentialMode(int iterations) { var policy = new BasicRetryPolicy(new EventHubsRetryOptions { MaximumRetries = 99, Delay = TimeSpan.FromMilliseconds(15), MaximumDelay = TimeSpan.FromHours(50000), Mode = EventHubsRetryMode.Exponential }); TimeSpan previousDelay = TimeSpan.Zero; for (var index = 0; index < iterations; ++index) { var variance = TimeSpan.FromSeconds((policy.Options.Delay.TotalSeconds * index) * policy.JitterFactor); TimeSpan?delay = policy.CalculateRetryDelay(Mock.Of <TimeoutException>(), index); Assert.That(delay.HasValue, Is.True, $"Iteration: { index } did not have a value."); Assert.That(delay.Value, Is.GreaterThan(previousDelay.Add(variance)), $"Iteration: { index } produced an unexpected delay."); previousDelay = delay.Value; } }
public async Task CreateBatchAsyncEnsuresMaximumMessageSizeIsPopulated() { var retryPolicy = new BasicRetryPolicy(new RetryOptions { TryTimeout = TimeSpan.FromSeconds(17) }); var producer = new Mock <AmqpProducer>("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), retryPolicy) { CallBase = true }; producer .Protected() .Setup <Task <SendingAmqpLink> >("CreateLinkAndEnsureProducerStateAsync", ItExpr.IsAny <string>(), ItExpr.IsAny <TimeSpan>(), ItExpr.IsAny <CancellationToken>()) .Callback(() => SetMaximumMessageSize(producer.Object, 512)) .Returns(Task.FromResult(new SendingAmqpLink(new AmqpLinkSettings()))) .Verifiable(); using TransportEventBatch batch = await producer.Object.CreateBatchAsync(new CreateBatchOptions (), default); producer.VerifyAll(); }