Skip to content

Commit dcfd183

Browse files
authored
Merge pull request #16 from Leefrost/refactoring-tests
Clean up memory cache tests
2 parents c01f868 + 98f9fdd commit dcfd183

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/HttpClient.Cache/InMemory/MemoryCacheOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace HttpClient.Cache.InMemory;
44

55
public class MemoryCacheOptions
66
{
7-
public TimeSpan ExpirationScanFrequency { get; set; } = TimeSpan.FromSeconds(1.0);
7+
public TimeSpan ExpirationScanFrequency { get; set; } = TimeSpan.FromMinutes(1.0);
88

99
public ISystemClock Clock { get; set; } = new SystemClock();
1010
}

tests/HttpClient.Cache.Tests/InMemory/MemoryCacheTests.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
using HttpClient.Cache.InMemory;
44

55
namespace HttpClient.Cache.Tests.InMemory;
6-
7-
[CollectionDefinition("Sequential", DisableParallelization = true)]
86
public class MemoryCacheTests
97
{
108
[Fact]
119
public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items()
1210
{
1311
var expiration = TimeSpan.FromHours(1);
14-
var options = new MemoryCacheOptions();
12+
var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) };
1513
var cache = new MemoryCache(options);
1614

1715
for (var i = 1; i <= 10; ++i)
@@ -34,18 +32,18 @@ public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items()
3432
[Fact]
3533
public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty()
3634
{
37-
var options = new MemoryCacheOptions();
35+
var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) };
3836
var cache = new MemoryCache(options);
3937

4038
using(var entry = cache.CreateEntry("key")){
41-
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3);
39+
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(2);
4240
entry.Value = $"value";
4341
}
4442

4543
using (new AssertionScope())
4644
{
4745
cache.Count.Should().Be(1);
48-
await Task.Delay(TimeSpan.FromSeconds(4));
46+
await Task.Delay(TimeSpan.FromSeconds(3));
4947

5048
var value = cache.TryGetValue("key", out var cacheEntry);
5149
value.Should().BeFalse();
@@ -58,7 +56,7 @@ public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty
5856
public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty()
5957
{
6058
var expiration = TimeSpan.FromSeconds(2);
61-
var options = new MemoryCacheOptions();
59+
var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) };
6260
var cache = new MemoryCache(options);
6361

6462
using(var entry = cache.CreateEntry("key")){
@@ -82,7 +80,7 @@ public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty()
8280
[Fact]
8381
public async Task CreateEntry_ExpireAbsoluteDate_CacheIsEmpty()
8482
{
85-
var options = new MemoryCacheOptions();
83+
var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) };
8684
var cache = new MemoryCache(options);
8785

8886
using(var entry = cache.CreateEntry("key")){

0 commit comments

Comments
 (0)