Skip to content

Commit 1d3bf0a

Browse files
author
Travis Whidden
committed
zzzprojects#764 Additional Tests, Missing TTL Update
1 parent 4ce4385 commit 1d3bf0a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/System.Linq.Dynamic.Core/Parser/ThreadSafeSlidingCache.cs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public bool TryGetValue(T1 key, out T2 value)
4040
if (DateTime.UtcNow <= valueAndExpiration.ExpirationTime)
4141
{
4242
value = valueAndExpiration.Value;
43+
_cache[key] = (value, DateTime.UtcNow.Add(_timeToLive));
4344
return true;
4445
}
4546
else

test/System.Linq.Dynamic.Core.Tests/Util/ConstantExpressionHelperTests.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@ public async Task TestConstantExpressionLeak()
1616

1717
var expressions = ConstantExpressionHelper.Expressions;
1818

19+
// Should contain
1920
if (!expressions.TryGetValue(2000, out _))
2021
{
2122
Assert.Fail("Cache was missing constant expression for 2000");
2223
}
23-
24+
25+
// wait half the expiry time
26+
await Task.Delay(TimeSpan.FromSeconds(ConstantExpressionHelper.Expressions.TimeToLive.TotalSeconds/2));
27+
if (!expressions.TryGetValue(2000, out _))
28+
{
29+
Assert.Fail("Cache was missing constant expression for 2000 (1)");
30+
}
31+
32+
// wait another half the expiry time, plus one second
33+
await Task.Delay(TimeSpan.FromSeconds((ConstantExpressionHelper.Expressions.TimeToLive.TotalSeconds / 2)+1));
34+
if (!expressions.TryGetValue(2000, out _))
35+
{
36+
Assert.Fail("Cache was missing constant expression for 2000 (2)");
37+
}
38+
2439
// Wait for the slide cache to expire, check on second later
2540
await Task.Delay(ConstantExpressionHelper.Expressions.TimeToLive.Add(TimeSpan.FromSeconds(1)));
2641

0 commit comments

Comments
 (0)