public async Task Given2Actors_WhenCreatedAndDeletedDifferentTask_ShouldPass() { int count = 0; int count2 = 0; const int max = 10; const int maxLoop = 10; IActorManager manager = new ActorManager(); manager.Register <ICache>(_ => new StringCache(y => CountControl(ref count, y))); manager.Register <ICache2>(_ => new StringCache2(y => CountControl(ref count2, y))); for (int loop = 0; loop < maxLoop; loop++) { _output.WriteLine($"Loop: {loop}"); await Enumerable.Range(0, max) .Select(x => new Task[] { Task.Run(async() => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = await manager.CreateProxy <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorManager().Should().Be(manager); }), Task.Run(async() => { ActorKey key2 = new ActorKey($"cache/test/{x}"); ICache2 cache2 = await manager.CreateProxy <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorManager().Should().Be(manager); }), }) .SelectMany(x => x) .WhenAll(); count.Should().Be(max); count2.Should().Be(max); await Enumerable.Range(0, max) .Select(x => new Task <bool>[] { Task.Run(async() => await manager.Deactivate <ICache>(new ActorKey($"cache/test/{x}"))), Task.Run(async() => await manager.Deactivate <ICache2>(new ActorKey($"cache/test/{x}"))), }) .SelectMany(x => x) .WhenAll(); count.Should().Be(0); count2.Should().Be(0); await manager.DeactivateAll(); count.Should().Be(0); count2.Should().Be(0); } }
public async Task Given2Actors_WhenCreatedAndDeleted_ShouldPass() { int count = 0; int count2 = 0; const int max = 10; IActorManager manager = new ActorManager(); manager.Register <ICache>(_ => new StringCache(y => CountControl(ref count, y))); manager.Register <ICache2>(_ => new StringCache2(y => CountControl(ref count2, y))); await Enumerable.Range(0, max) .Select(async x => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = await manager.CreateProxy <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorManager().Should().Be(manager); ActorKey key2 = new ActorKey($"cache/test/{x}"); ICache2 cache2 = await manager.CreateProxy <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorManager().Should().Be(manager); }) .WhenAll(); count.Should().Be(max); count2.Should().Be(max); await Enumerable.Range(0, max) .Select(async x => { ActorKey key = new ActorKey($"cache/test/{x}"); (await manager.Deactivate <ICache>(key)).Should().BeTrue(); ActorKey key2 = new ActorKey($"cache/test/{x}"); (await manager.Deactivate <ICache2>(key2)).Should().BeTrue(); }) .WhenAll(); count.Should().Be(0); count2.Should().Be(0); await manager.DeactivateAll(); count.Should().Be(0); count2.Should().Be(0); }