Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetOrAdd(...) fails after GetOrAddAsync(...) #12

Closed
baddonkey opened this issue Dec 8, 2016 · 2 comments
Closed

GetOrAdd(...) fails after GetOrAddAsync(...) #12

baddonkey opened this issue Dec 8, 2016 · 2 comments

Comments

@baddonkey
Copy link

Please, consider the following failing sample unit test:

        [Test]
        public async Task GetOrAddFollowinGetOrAddAsyncTryOut()
        {
            Func<Task<ComplexTestObject>> fetchAsync = () => Task.FromResult(testObject);
            await sut.GetOrAddAsync(TestKey, fetchAsync);
            var actualAsync = await sut.GetAsync<ComplexTestObject>(TestKey);
            Assert.IsNotNull(actualAsync);
            Assert.That(actualAsync, Is.EqualTo(testObject));

            Func<ComplexTestObject> fetchSync = () => testObject;
            sut.GetOrAdd(TestKey, fetchSync);
            var actualSync = sut.Get<ComplexTestObject>(TestKey);
            Assert.IsNotNull(actualSync); // actualSync == null
        }

Note:

  • Fails on last assertion as actualSync is null.
  • Having the GetOrAdd before GetOrAddAsync, the test would succeed.

I assume that the private method UnwrapLazy is not considering the new AsyncLazy enhancements from September. Would be great if you could apply a fix for that, I would like to use this library in a mixed sync/async environment.

Thanks for sharing this library, great work.

Best regards, BadDonkey

@alastairtree
Copy link
Owner

Fixed in version 0.7.1, see https://www.nuget.org/packages/lazycache

@baddonkey
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants