Skip to content

Commit

Permalink
bug: remove tests using AddExpirationToken inside item factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairtree committed Sep 19, 2020
1 parent 476eb8b commit 129e798
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions LazyCache.UnitTests/CachingServiceMemoryCacheProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,94 +789,6 @@ public async Task GetOrAddAsyncWithAbsoluteOffsetExpiryInTheDelegateUsingTimeSpa
Assert.That(expiredResult, Is.Null);
}

[Test]
public void GetOrAddWithCancellationExpiryInTheDelegateDoesExpireItems()
{
var tokenSource = new CancellationTokenSource();
var expireToken = new CancellationChangeToken(tokenSource.Token);
var validResult = sut.GetOrAdd(
TestKey,
entry =>
{
entry.AddExpirationToken(expireToken);
return new ComplexTestObject();
}
);
// trigger expiry
tokenSource.Cancel();
var expiredResult = sut.Get<ComplexTestObject>(TestKey);

Assert.That(validResult, Is.Not.Null);
Assert.That(expiredResult, Is.Null);
}

[Test]
public async Task GetOrAddAsyncWithCancellationExpiryInTheDelegateDoesExpireItems()
{
var tokenSource = new CancellationTokenSource();
var expireToken = new CancellationChangeToken(tokenSource.Token);
var validResult = await sut.GetOrAddAsync(
TestKey,
entry =>
{
entry.AddExpirationToken(expireToken);
return Task.FromResult(new ComplexTestObject());
}
);
// trigger expiry
tokenSource.Cancel();
var expiredResult = sut.Get<ComplexTestObject>(TestKey);

Assert.That(validResult, Is.Not.Null);
Assert.That(expiredResult, Is.Null);
}

[Test]
public void GetOrAddWithCancellationExpiryBasedOnTimerInTheDelegateDoesExpireItems()
{
var millisecondsCacheDuration = 100;
var tokenSource = new CancellationTokenSource(millisecondsCacheDuration);
var expireToken = new CancellationChangeToken(tokenSource.Token);
var validResult = sut.GetOrAdd(
TestKey,
entry =>
{
entry.AddExpirationToken(expireToken);
return new ComplexTestObject();
}
);
// trigger expiry
Thread.Sleep(TimeSpan.FromMilliseconds(millisecondsCacheDuration + 50));

var expiredResult = sut.Get<ComplexTestObject>(TestKey);

Assert.That(validResult, Is.Not.Null);
Assert.That(expiredResult, Is.Null);
}

[Test]
public async Task GetOrAddAsyncWithCancellationExpiryBasedOnTimerInTheDelegateDoesExpireItems()
{
var millisecondsCacheDuration = 200;
var tokenSource = new CancellationTokenSource(millisecondsCacheDuration);
var expireToken = new CancellationChangeToken(tokenSource.Token);
var validResult = await sut.GetOrAddAsync(
TestKey,
entry =>
{
entry.AddExpirationToken(expireToken);
return Task.FromResult(new ComplexTestObject());
}
);
// trigger expiry
Thread.Sleep(TimeSpan.FromMilliseconds(millisecondsCacheDuration + 100));

var expiredResult = sut.Get<ComplexTestObject>(TestKey);

Assert.That(validResult, Is.Not.Null);
Assert.That(expiredResult, Is.Null);
}

[Test]
public void GetOrAddWithCancellationExpiryBasedOnTimerAndCallbackInTheDelegateDoesExpireItemsAndFireTheCallback()
{
Expand Down

0 comments on commit 129e798

Please sign in to comment.