Skip to content

Commit

Permalink
Another commit on trying to stabilize tests that verify expiration be…
Browse files Browse the repository at this point in the history
…cause of test runner side effects
  • Loading branch information
neon-sunset committed Jan 20, 2023
1 parent 9659ea8 commit 4dd1721
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/FastCache.CachedTests/Cached_ExpirationPermutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ public sealed class CachedTests_ExpirationPermutations
[InlineData(2500)]
public async Task Cached_TryGet_ReturnsValueBeforeExpiration_DoesNotReturnAfter(int milliseconds)
{
const int delayTolerance = 100;
const int delayTolerance = 200;

var assertDelay = Math.Max(0, milliseconds - delayTolerance);

var key = GetTestKey(milliseconds);
var value = GetRandomString();
value.Cache(key, TimeSpan.FromMilliseconds(milliseconds));

await Task.Delay(Math.Max(0, milliseconds - delayTolerance));
await Task.Delay(assertDelay);
var foundBefore = Cached<string>.TryGet(key, out var cachedBefore);

Assert.True(foundBefore);
Assert.Equal(value, cachedBefore);

await Task.Delay(delayTolerance + 1);
await Task.Delay(milliseconds - assertDelay + 1);
var foundAfter = Cached<string>.TryGet(key, out _);

Assert.False(foundAfter);
Expand Down

0 comments on commit 4dd1721

Please sign in to comment.