Пример #1
0
            public void Should_unblock_blocked_wait_thread_when_release_forever()
            {
                var limiter = new Limiter(0, 10, log);

                var waitTasks = new []
                {
                    new Task(() => limiter.WaitFree(), TaskCreationOptions.LongRunning),
                    new Task(() => limiter.WaitFree(), TaskCreationOptions.LongRunning),
                    new Task(() => limiter.WaitFree(), TaskCreationOptions.LongRunning)
                };

                Start(waitTasks);
                var whenAll = Task.WhenAll(waitTasks);
                var whenAny = Task.WhenAny(waitTasks);

                whenAll.Wait(200);
                whenAll.IsCompleted.Should().BeFalse();

                limiter.ReleaseForever();

                whenAny.Wait(100);
                whenAny.IsCompleted.Should().BeTrue();
                whenAll.Wait(100);
                whenAll.IsCompleted.Should().BeTrue();

                limiter.CurrentFreeNumber.Should().Be(10);
            }
Пример #2
0
            public void Should_set_release_into_max_value()
            {
                var limiter = new Limiter(0, 10);

                limiter.ReleaseForever();

                limiter.CurrentFreeNumber.Should().Be(10);
            }
Пример #3
0
            public void Should_not_allow_to_decreases_by_waits()
            {
                var limiter = new Limiter(0, 2);

                limiter.ReleaseForever();

                limiter.WaitFree();
                limiter.WaitFree();
                limiter.WaitFree();
                limiter.CurrentFreeNumber.Should().Be(2);
            }