-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
SqlServerRetryingExecutionStrategyTests.cs
45 lines (39 loc) · 1.57 KB
/
SqlServerRetryingExecutionStrategyTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ReSharper disable InconsistentNaming
namespace Microsoft.EntityFrameworkCore.Storage;
public class SqlServerRetryingExecutionStrategyTests
{
[ConditionalFact]
public void GetNextDelay_returns_shorter_delay_for_InMemory_transient_errors()
{
var strategy = new TestSqlServerRetryingExecutionStrategy(CreateContext());
var inMemoryError = SqlExceptionFactory.CreateSqlException(41302);
var delays = new List<TimeSpan>();
var delay = strategy.GetNextDelay(inMemoryError);
while (delay != null)
{
delays.Add(delay.Value);
delay = strategy.GetNextDelay(inMemoryError);
}
var expectedDelays = new List<TimeSpan>
{
TimeSpan.FromMilliseconds(0),
TimeSpan.FromMilliseconds(1),
TimeSpan.FromMilliseconds(3),
TimeSpan.FromMilliseconds(7),
TimeSpan.FromMilliseconds(15),
TimeSpan.FromMilliseconds(31)
};
Assert.Equal(expectedDelays.Count, delays.Count);
for (var i = 0; i < expectedDelays.Count; i++)
{
Assert.True(
Math.Abs((delays[i] - expectedDelays[i]).TotalMilliseconds)
<= expectedDelays[i].TotalMilliseconds * 0.1 + 1,
$"Expected: {expectedDelays[i]}; Actual: {delays[i]}");
}
}
protected DbContext CreateContext()
=> SqlServerTestHelpers.Instance.CreateContext();
}