Skip to content

[BUG] IsFailSafeEnabled required to be set true in DefaultEntryOptions #333

@waynebrantley

Description

@waynebrantley

@jodydonetti Really amazing work. So many features and all pretty simple to use.

It appears that if the DefaultEntryOptions do not turn on Fail Safe, it cannot be turned on.
This fails for the 'false' case and succeeds for the 'true' case.

Is this expected behavior

    [TestCase(true)]
    [TestCase(false)]
    public void LocalFailSafeEnabled(bool setDefaultFailSafe)
    {
        var services = new ServiceCollection();
        services.AddMemoryCache();
        var cacheBuilder = services.AddFusionCache();
        cacheBuilder.WithDefaultEntryOptions(new FusionCacheEntryOptions
        {
            Duration = TimeSpan.FromHours(2), 
            IsFailSafeEnabled = setDefaultFailSafe,
            FailSafeMaxDuration = TimeSpan.FromDays(1), 
            FailSafeThrottleDuration = TimeSpan.FromSeconds(30),
            FactorySoftTimeout = TimeSpan.FromMilliseconds(100),
            FactoryHardTimeout = TimeSpan.FromMinutes(2),
        });

        var serviceProvider = services.BuildServiceProvider();
        var fusionCache = serviceProvider.GetRequiredService<IFusionCache>();
        
        var initialDateTime = fusionCache.GetOrSet("TEST",  _ =>
        {
            Thread.Sleep(TimeSpan.FromSeconds(3));
            return DateTime.Now;
        }, options => options.SetDuration(TimeSpan.FromSeconds(30)).SetFailSafe(true, TimeSpan.FromHours(2), TimeSpan.FromSeconds(30)).SetFactoryTimeouts(TimeSpan.FromMilliseconds(100)));

        var cachedDateTime = fusionCache.GetOrSet("TEST",  _ =>
        {
            Thread.Sleep(TimeSpan.FromSeconds(3));
            return DateTime.Now;
        }, options => options.SetDuration(TimeSpan.FromSeconds(30)).SetFailSafe(true, TimeSpan.FromHours(2), TimeSpan.FromSeconds(30)).SetFactoryTimeouts(TimeSpan.FromMilliseconds(100)));

        Assert.That(initialDateTime, Is.EqualTo(cachedDateTime));
     
        //now expire the cache
        fusionCache.Expire("TEST");
        var shouldUseExpiredValue = fusionCache.GetOrSet("TEST",  _ =>
        {
            Thread.Sleep(TimeSpan.FromSeconds(3));
            return DateTime.Now;
        }, options => options.SetDuration(TimeSpan.FromSeconds(30)).SetFailSafe(true, TimeSpan.FromHours(2), TimeSpan.FromSeconds(30)).SetFactoryTimeouts(TimeSpan.FromMilliseconds(100)));
     
        Assert.That(shouldUseExpiredValue, Is.EqualTo(initialDateTime));
        
        Thread.Sleep(TimeSpan.FromSeconds(3)); //should be enough time for it to have finished

        var shouldBeNewValue = fusionCache.GetOrSet("TEST",  _ =>
        {
            Thread.Sleep(TimeSpan.FromSeconds(3));
            return DateTime.Now;
        }, options => options.SetDuration(TimeSpan.FromSeconds(30)).SetFailSafe(true, TimeSpan.FromHours(2), TimeSpan.FromSeconds(30)).SetFactoryTimeouts(TimeSpan.FromMilliseconds(100)));

        Assert.That(shouldBeNewValue, Is.Not.EqualTo(initialDateTime));
    }

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions