Skip to content

Commit 48ce79e

Browse files
committed
Enabled perf tests as they are fast, added tests for remove all
1 parent 4d45ccf commit 48ce79e

File tree

4 files changed

+118
-6
lines changed

4 files changed

+118
-6
lines changed

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,64 @@ public virtual async Task CanUseScopedCachesAsync()
357357
}
358358
}
359359

360+
public virtual async Task CanRemoveAllAsync()
361+
{
362+
const int COUNT = 10000;
363+
364+
var cache = GetCacheClient();
365+
if (cache == null)
366+
return;
367+
368+
using (cache)
369+
{
370+
await cache.RemoveAllAsync();
371+
372+
var dictionary = Enumerable.Range(0, COUNT).ToDictionary(i => $"remove-all:{i}");
373+
374+
var sw = Stopwatch.StartNew();
375+
await cache.SetAllAsync(dictionary);
376+
sw.Stop();
377+
_logger.LogInformation("Set All Time: {Elapsed:g}", sw.Elapsed);
378+
379+
sw = Stopwatch.StartNew();
380+
Assert.Equal(COUNT, await cache.RemoveAllAsync());
381+
sw.Stop();
382+
_logger.LogInformation("Remove All Time: {Elapsed:g}", sw.Elapsed);
383+
384+
Assert.False(await cache.ExistsAsync("remove-all:0"));
385+
Assert.False(await cache.ExistsAsync($"remove-all:{COUNT - 1}"));
386+
}
387+
}
388+
389+
public virtual async Task CanRemoveAllKeysAsync()
390+
{
391+
const int COUNT = 10000;
392+
393+
var cache = GetCacheClient();
394+
if (cache == null)
395+
return;
396+
397+
using (cache)
398+
{
399+
await cache.RemoveAllAsync();
400+
401+
var dictionary = Enumerable.Range(0, COUNT).ToDictionary(i => $"remove-all-keys:{i}");
402+
403+
var sw = Stopwatch.StartNew();
404+
await cache.SetAllAsync(dictionary);
405+
sw.Stop();
406+
_logger.LogInformation("Set All Time: {Elapsed:g}", sw.Elapsed);
407+
408+
sw = Stopwatch.StartNew();
409+
Assert.Equal(COUNT, await cache.RemoveAllAsync(dictionary.Keys));
410+
sw.Stop();
411+
_logger.LogInformation("Remove All Time: {Elapsed:g}", sw.Elapsed);
412+
413+
Assert.False(await cache.ExistsAsync("remove-all-keys:0"));
414+
Assert.False(await cache.ExistsAsync($"remove-all-keys:{COUNT - 1}"));
415+
}
416+
}
417+
360418
public virtual async Task CanRemoveByPrefixAsync()
361419
{
362420
var cache = GetCacheClient();
@@ -1036,7 +1094,7 @@ public virtual async Task MeasureThroughputAsync()
10361094
await cache.SetAsync("test", 13422);
10371095
await cache.SetAsync("flag", true);
10381096
Assert.Equal(13422, (await cache.GetAsync<int>("test")).Value);
1039-
Assert.Null(await cache.GetAsync<int>("test2"));
1097+
Assert.False((await cache.GetAsync<int>("test2")).HasValue);
10401098
Assert.True((await cache.GetAsync<bool>("flag")).Value);
10411099
}
10421100
sw.Stop();

src/Foundatio.TestHarness/Caching/HybridCacheClientTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ public override Task CanSetAndGetObjectAsync()
8181
return base.CanSetAndGetObjectAsync();
8282
}
8383

84+
[Fact]
85+
public override Task CanRemoveAllAsync()
86+
{
87+
return base.CanRemoveAllAsync();
88+
}
89+
90+
[Fact]
91+
public override Task CanRemoveAllKeysAsync()
92+
{
93+
return base.CanRemoveAllKeysAsync();
94+
}
95+
8496
[Fact]
8597
public override Task CanRemoveByPrefixAsync()
8698
{

tests/Foundatio.Tests/Caching/InMemoryCacheClientTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public override Task CanSetAndGetObjectAsync()
7777
return base.CanSetAndGetObjectAsync();
7878
}
7979

80+
[Fact]
81+
public override Task CanRemoveAllAsync()
82+
{
83+
return base.CanRemoveAllAsync();
84+
}
85+
86+
[Fact]
87+
public override Task CanRemoveAllKeysAsync()
88+
{
89+
return base.CanRemoveAllKeysAsync();
90+
}
91+
8092
[Fact]
8193
public override Task CanRemoveByPrefixAsync()
8294
{
@@ -187,10 +199,28 @@ public override Task CanManageListRemoveExpirationAsync()
187199
return base.CanManageListRemoveExpirationAsync();
188200
}
189201

202+
[Fact]
203+
public override Task MeasureThroughputAsync()
204+
{
205+
return base.MeasureThroughputAsync();
206+
}
207+
208+
[Fact]
209+
public override Task MeasureSerializerSimpleThroughputAsync()
210+
{
211+
return base.MeasureSerializerSimpleThroughputAsync();
212+
}
213+
214+
[Fact]
215+
public override Task MeasureSerializerComplexThroughputAsync()
216+
{
217+
return base.MeasureSerializerComplexThroughputAsync();
218+
}
219+
190220
[Fact]
191221
public async Task CanSetMaxItems()
192222
{
193-
// run in tight loop so that the code is warmed up and we can catch timing issues
223+
// run in a tight loop so that the code is warmed up and we can catch timing issues
194224
for (int x = 0; x < 5; x++)
195225
{
196226
var cache = new InMemoryCacheClient(o => o.MaxItems(10).CloneValues(true));

tests/Foundatio.Tests/Caching/InMemoryHybridCacheClientTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using Foundatio.Caching;
33
using Foundatio.Messaging;
44
using Microsoft.Extensions.Logging;
@@ -34,6 +34,18 @@ public override Task CanTryGetAsync()
3434
return base.CanTryGetAsync();
3535
}
3636

37+
[Fact]
38+
public override Task CanRemoveAllAsync()
39+
{
40+
return base.CanRemoveAllAsync();
41+
}
42+
43+
[Fact]
44+
public override Task CanRemoveAllKeysAsync()
45+
{
46+
return base.CanRemoveAllKeysAsync();
47+
}
48+
3749
[Fact]
3850
public override Task CanRemoveByPrefixAsync()
3951
{
@@ -90,19 +102,19 @@ public override Task WillWorkWithSets()
90102
return base.WillWorkWithSets();
91103
}
92104

93-
[Fact(Skip = "Performance Test")]
105+
[Fact]
94106
public override Task MeasureThroughputAsync()
95107
{
96108
return base.MeasureThroughputAsync();
97109
}
98110

99-
[Fact(Skip = "Performance Test")]
111+
[Fact]
100112
public override Task MeasureSerializerSimpleThroughputAsync()
101113
{
102114
return base.MeasureSerializerSimpleThroughputAsync();
103115
}
104116

105-
[Fact(Skip = "Performance Test")]
117+
[Fact]
106118
public override Task MeasureSerializerComplexThroughputAsync()
107119
{
108120
return base.MeasureSerializerComplexThroughputAsync();

0 commit comments

Comments
 (0)