public void GetOrCreateTest() { var target = new ActorPool(); var countdownEvent = new CountdownEvent(3); using (IActor actor = target.GetOrCreate("a")) { Task Func() { countdownEvent.Signal(); return(Task.CompletedTask); } actor.Enqueue(Func); actor.Enqueue(Func); actor.Enqueue(Func); } countdownEvent.Wait(TimeSpan.FromSeconds(1)).Should().Be(true); Thread.Sleep(100); target.TakeSnapshot().Count.Should().Be(0); }
public void active_actor_should_have_reference() { // arrange var target = new ActorPool(); // act using var actor = target.GetOrCreate(Guid.NewGuid().ToString()); // assert target.TakeSnapshot().Count.Should().Be(1); }
public void active_actor_should_have_multiple_reference() { // arrange var target = new ActorPool(); var id = Guid.NewGuid().ToString(); // act using var actor = target.GetOrCreate(id); using var actor2 = target.GetOrCreate(id); // assert ActorPoolSnapshot snapshot = target.TakeSnapshot(); snapshot.Count.Should().Be(1); snapshot[id].QueuedWork.Should().Be(0); snapshot[id].References.Should().Be(2); }