コード例 #1
0
ファイル: ActorPoolTests.cs プロジェクト: bitanetanel/Mictor
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }