-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from sebslsch/master
Fixed concurrency errors in MemoryCache when using dotnetcore
- Loading branch information
Showing
2 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Framework/CQRSlite.Tests/Caching/When_creating_and_using_repositories_in_parallel.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,46 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using CQRSlite.Caching; | ||
using CQRSlite.Domain; | ||
using CQRSlite.Tests.Substitutes; | ||
using Xunit; | ||
|
||
namespace CQRSlite.Tests.Caching | ||
{ | ||
public class When_creating_and_using_repositories_in_parallel | ||
{ | ||
private readonly TestInMemoryEventStore _testStore; | ||
|
||
private readonly ICache _cache; | ||
|
||
private Exception _exception; | ||
|
||
public When_creating_and_using_repositories_in_parallel() | ||
{ | ||
_testStore = new TestInMemoryEventStore(); | ||
_cache = new CQRSlite.Caching.MemoryCache(); | ||
|
||
int numberOfAggregates = 10; | ||
int numberOfIterations = 200; | ||
|
||
Task[] tasks = Enumerable.Range(0, numberOfAggregates).Select(_ => Task.Run(async () => | ||
{ | ||
var aggregateId = Guid.NewGuid(); | ||
for (int iteration = 0; iteration < numberOfIterations; iteration++) | ||
{ | ||
var cacheRepository = new CacheRepository(new Repository(_testStore), _testStore, _cache); | ||
await cacheRepository.Save(new TestAggregate(aggregateId)); | ||
} | ||
})).ToArray(); | ||
|
||
_exception = Record.Exception(() => Task.WaitAll(tasks)); | ||
} | ||
|
||
[Fact] | ||
public void Should_not_cause_concurrency_issues() | ||
{ | ||
Assert.Null(_exception); | ||
} | ||
} | ||
} |
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