Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jodydonetti authored Aug 18, 2024
2 parents 4c4547b + 1c1c726 commit 9fca327
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/ZiggyCreatures.FusionCache.Tests/MemoryLevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ public void ReturnsStaleDataWhenFactoryFails()
public async Task ReturnsStaleDataWhenFactoryFailsWithoutExceptionAsync()
{
var errorMessage = "Sloths are cool";
var throttleDuration = TimeSpan.FromSeconds(1);

var options = new FusionCacheOptions();
options.DefaultEntryOptions.Duration = TimeSpan.FromMilliseconds(100);
options.DefaultEntryOptions.IsFailSafeEnabled = true;
options.DefaultEntryOptions.FailSafeThrottleDuration = TimeSpan.FromSeconds(1);
options.DefaultEntryOptions.FailSafeThrottleDuration = throttleDuration;
options.DefaultEntryOptions.FailSafeMaxDuration = TimeSpan.FromMinutes(10);

using var cache = new FusionCache(options);

var initialValue = await cache.GetOrSetAsync<int>("foo", async _ => 42);
Expand All @@ -89,7 +93,7 @@ public async Task ReturnsStaleDataWhenFactoryFailsWithoutExceptionAsync()

Assert.Equal(initialValue, newValue);

await Task.Delay(options.DefaultEntryOptions.FailSafeThrottleDuration);
await Task.Delay(throttleDuration.PlusALittleBit());

Exception? exc = null;
try
Expand All @@ -104,6 +108,8 @@ public async Task ReturnsStaleDataWhenFactoryFailsWithoutExceptionAsync()
{
exc = exc1;
}

Assert.NotNull(exc);
Assert.IsType<FusionCacheFactoryException>(exc);
Assert.Equal(errorMessage, exc.Message);
}
Expand All @@ -112,10 +118,14 @@ public async Task ReturnsStaleDataWhenFactoryFailsWithoutExceptionAsync()
public void ReturnsStaleDataWhenFactoryFailsWithoutException()
{
var errorMessage = "Sloths are cool";
var throttleDuration = TimeSpan.FromSeconds(1);

var options = new FusionCacheOptions();
options.DefaultEntryOptions.Duration = TimeSpan.FromMilliseconds(100);
options.DefaultEntryOptions.IsFailSafeEnabled = true;
options.DefaultEntryOptions.FailSafeThrottleDuration = TimeSpan.FromSeconds(1);
options.DefaultEntryOptions.FailSafeThrottleDuration = throttleDuration;
options.DefaultEntryOptions.FailSafeMaxDuration = TimeSpan.FromMinutes(10);

using var cache = new FusionCache(options);

var initialValue = cache.GetOrSet<int>("foo", _ => 42);
Expand All @@ -126,7 +136,7 @@ public void ReturnsStaleDataWhenFactoryFailsWithoutException()

Assert.Equal(initialValue, newValue);

Thread.Sleep(options.DefaultEntryOptions.FailSafeThrottleDuration);
Thread.Sleep(throttleDuration.PlusALittleBit());

Exception? exc = null;
try
Expand All @@ -141,6 +151,8 @@ public void ReturnsStaleDataWhenFactoryFailsWithoutException()
{
exc = exc1;
}

Assert.NotNull(exc);
Assert.IsType<FusionCacheFactoryException>(exc);
Assert.Equal(errorMessage, exc.Message);
}
Expand Down

0 comments on commit 9fca327

Please sign in to comment.