-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using BitFaster.Caching.Lru; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace BitFaster.Caching.UnitTests.Atomic | ||
{ | ||
[Collection("Soak")] | ||
public class AtomicFactorySoakTests | ||
{ | ||
[Fact] | ||
public async Task WhenGetOrAddIsConcurrentValuesCreatedAtomically() | ||
{ | ||
var cache = new ConcurrentLruBuilder<int, int>().WithAtomicGetOrAdd().WithCapacity(1024).Build(); | ||
|
||
var counters = new int[4]; | ||
|
||
await Threaded.Run(4, (r) => | ||
{ | ||
for (int i = 0; i < 1024; i++) | ||
{ | ||
cache.GetOrAdd(i, k => { counters[r]++; return k; }); | ||
} | ||
}); | ||
|
||
counters.Sum(x => x).Should().Be(1024); | ||
Check failure on line 27 in BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs GitHub Actions / test results (win net4.8)BitFaster.Caching.UnitTests.Atomic.AtomicFactorySoakTests ► WhenGetOrAddIsConcurrentValuesCreatedAtomically
Raw output
|
||
} | ||
} | ||
} |