public async Task Given2Actors_WhenCreatedAndDeletedDifferentTask_ShouldPass() { int count = 0; int count2 = 0; const int max = 10; const int maxLoop = 10; using IActorHost actorHost = new ActorHost(_loggerFactory) .Register <ICache>(() => new StringCache(y => CountControl(ref count, y))) .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(() => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = actorHost.GetActor <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorHost().Should().Be(actorHost); }), Task.Run(() => { ActorKey key2 = new ActorKey($"cache/test/{x}"); ICache2 cache2 = actorHost.GetActor <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorHost().Should().Be(actorHost); }), }) .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 actorHost.Deactivate <ICache>(new ActorKey($"cache/test/{x}"))), Task.Run(async() => await actorHost.Deactivate <ICache2>(new ActorKey($"cache/test/{x}"))), }) .SelectMany(x => x) .WhenAll(); count.Should().Be(0); count2.Should().Be(0); await actorHost.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; using IActorHost actorHost = new ActorHost(_loggerFactory) .Register <ICache>(() => new StringCache(y => CountControl(ref count, y))) .Register <ICache2>(() => new StringCache2(y => CountControl(ref count2, y))); Enumerable.Range(0, max) .ForEach(x => { ActorKey key = new ActorKey($"cache/test/{x}"); ICache cache = actorHost.GetActor <ICache>(key); cache.GetActorKey().Should().Be(key); cache.GetActorHost().Should().Be(actorHost); ActorKey key2 = new ActorKey($"cache/test/{x}"); ICache2 cache2 = actorHost.GetActor <ICache2>(key2); cache2.GetActorKey().Should().Be(key2); cache2.GetActorHost().Should().Be(actorHost); }); count.Should().Be(max); count2.Should().Be(max); await Enumerable.Range(0, max) .Select(async x => { ActorKey key = new ActorKey($"cache/test/{x}"); (await actorHost.Deactivate <ICache>(key)).Should().BeTrue(); ActorKey key2 = new ActorKey($"cache/test/{x}"); (await actorHost.Deactivate <ICache2>(key2)).Should().BeTrue(); }) .WhenAll(); count.Should().Be(0); count2.Should().Be(0); await actorHost.DeactivateAll(); count.Should().Be(0); count2.Should().Be(0); }