Skip to content

Commit

Permalink
KCL-1222 Fix timing issue in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiaskamenicky authored and Tobias Kamenicky committed Oct 3, 2019
1 parent e92c06b commit 240f138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions Kentico.Kontent.Delivery.Tests/DeliveryClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void GetStronglyTypedGenericWithAttributesResponse()
A.CallTo(() => _mockTypeProvider.GetType("complete_content_type"))
.ReturnsLazily(() => typeof(ContentItemModelWithAttributes));
A.CallTo(() => _mockTypeProvider.GetType("homepage")).ReturnsLazily(() => typeof(Homepage));

ContentItemModelWithAttributes item = (ContentItemModelWithAttributes)client.GetItemAsync<object>("complete_content_item").Result.Item;

// Assert
Expand Down Expand Up @@ -1304,8 +1304,6 @@ public async void RetryPolicy_Disabled_DoesNotRetry()
var client = DeliveryClientFactory.GetMockedDeliveryClientWithOptions(options, _mockHttp);
var retryPolicy = A.Fake<IRetryPolicy>();
A.CallTo(() => client.RetryPolicyProvider.GetRetryPolicy()).Returns(retryPolicy);
A.CallTo(() => retryPolicy.ExecuteAsync(A<Func<Task<HttpResponseMessage>>>._))
.ReturnsLazily(c => c.GetArgument<Func<Task<HttpResponseMessage>>>(0)());

await Assert.ThrowsAsync<DeliveryException>(async () => await client.GetItemsAsync());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ public async Task ExecuteAsync_RecoversAfterNotSuccessStatusCode()
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(2, client.TimesCalled);
Assert.True(stopwatch.Elapsed > 0.8 * options.DeltaBackoff);
Assert.True(stopwatch.Elapsed < options.MaxCumulativeWaitTime);
}

[Fact]
public async Task ExecuteAsync_RecoversAfterException()
{
var options = new RetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(500)
DeltaBackoff = TimeSpan.FromMilliseconds(100)
};
var retryPolicy = new DefaultRetryPolicy(options);
var client = new FakeSender()
Expand All @@ -68,7 +67,6 @@ public async Task ExecuteAsync_RecoversAfterException()
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(2, client.TimesCalled);
Assert.True(stopwatch.Elapsed > 0.8 * options.DeltaBackoff);
Assert.True(stopwatch.Elapsed < options.MaxCumulativeWaitTime);
}

[Fact]
Expand Down Expand Up @@ -119,7 +117,7 @@ public async Task ExecuteAsync_ThrottledRequest_NoHeader_GetsNextWaitTime(HttpSt
{
var options = new RetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(6),
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
};
var retryPolicy = new DefaultRetryPolicy(options);
Expand All @@ -140,7 +138,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithNotPositiveD
{
var options = new RetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(6),
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
};
var retryPolicy = new DefaultRetryPolicy(options);
Expand All @@ -161,7 +159,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithPastDate_Get
{
var options = new RetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(6),
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
};
var retryPolicy = new DefaultRetryPolicy(options);
Expand Down Expand Up @@ -240,7 +238,6 @@ public async Task ExecuteAsync_RetriesForCertainStatusCodes(HttpStatusCode statu
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(2, client.TimesCalled);
Assert.True(stopwatch.Elapsed > 0.8 * options.DeltaBackoff);
Assert.True(stopwatch.Elapsed < options.MaxCumulativeWaitTime);
}

[Theory]
Expand All @@ -263,8 +260,8 @@ public async Task ExecuteAsync_RetriesForCertainExceptions(Exception exception)
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(2, client.TimesCalled);
Assert.True(stopwatch.Elapsed > 0.8 * options.DeltaBackoff);
Assert.True(stopwatch.Elapsed < options.MaxCumulativeWaitTime);
}

private static Exception GetExceptionFromStatus(WebExceptionStatus status) => new HttpRequestException("Exception", new WebException(string.Empty, status));
public static readonly object[][] RetriedExceptions =
{
Expand Down

0 comments on commit 240f138

Please sign in to comment.