Skip to content

Commit

Permalink
Add ReThrowDistributedCacheExceptions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jodydonetti committed Jul 12, 2022
1 parent e1f264c commit 6e5c6a8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/ZiggyCreatures.FusionCache.Tests/MultiLevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,55 @@ public void DistributedCacheWireVersionNoneModeWorks(SerializerType serializerTy
{
_DistributedCacheWireVersionModifierWorks(serializerType, CacheKeyModifierMode.None);
}

[Theory]
[InlineData(SerializerType.NewtonsoftJson)]
[InlineData(SerializerType.SystemTextJson)]
public async Task ReThrowsDistributedCacheErrorsAsync(SerializerType serializerType)
{
var distributedCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
var chaosDistributedCache = new ChaosDistributedCache(distributedCache);

chaosDistributedCache.SetAlwaysThrow();
using var fusionCache = new FusionCache(new FusionCacheOptions());
fusionCache.DefaultEntryOptions.ReThrowDistributedCacheExceptions = true;

fusionCache.SetupDistributedCache(chaosDistributedCache, GetSerializer(serializerType));

await Assert.ThrowsAsync<ChaosException>(async () =>
{
await fusionCache.SetAsync<int>("foo", 42);
});

await Assert.ThrowsAsync<ChaosException>(async () =>
{
_ = await fusionCache.TryGetAsync<int>("bar");
});
}

[Theory]
[InlineData(SerializerType.NewtonsoftJson)]
[InlineData(SerializerType.SystemTextJson)]
public void ReThrowsDistributedCacheErrors(SerializerType serializerType)
{
var distributedCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
var chaosDistributedCache = new ChaosDistributedCache(distributedCache);

chaosDistributedCache.SetAlwaysThrow();
using var fusionCache = new FusionCache(new FusionCacheOptions());
fusionCache.DefaultEntryOptions.ReThrowDistributedCacheExceptions = true;

fusionCache.SetupDistributedCache(chaosDistributedCache, GetSerializer(serializerType));

Assert.Throws<ChaosException>(() =>
{
fusionCache.Set<int>("foo", 42);
});

Assert.Throws<ChaosException>(() =>
{
_ = fusionCache.TryGet<int>("bar");
});
}
}
}

0 comments on commit 6e5c6a8

Please sign in to comment.