Пример #1
0
        public async Task PushToLimitedListWithFunc()
        {
            var asyncEnum = new ReplayAsyncEnumerable <int>();
            var list      = new List <int>();
            var max       = 5;
            var task      = asyncEnum.PushToList(list, () => max).LastAsync();

            Assert.Empty(list);

            for (int i = 0; i < 7; i++)
            {
                await asyncEnum.Next(i);
            }

            await Task.Delay(500);

            Assert.Equal(5, list.Count);

            max = 2;

            for (int i = 0; i < 4; i++)
            {
                await asyncEnum.Next(i);
            }

            await asyncEnum.Complete();

            await task;

            Assert.Equal(2, list.Count);
        }
        public async void Unbounded_2_Consumers()
        {
            var push = new ReplayAsyncEnumerable <int>();

            var en1 = push.GetAsyncEnumerator();
            var en2 = push.GetAsyncEnumerator();

            var task1 = Task.Run(async() =>
            {
                await en1.AssertResult(1, 2, 3, 4, 5);
            });
            var task2 = Task.Run(async() =>
            {
                await en2.AssertResult(1, 2, 3, 4, 5);
            });

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Complete();

            await task1;
            await task2;
        }
        public async void TimedSized_2_Consumers_Error()
        {
            var push = new ReplayAsyncEnumerable <int>(10, TimeSpan.FromHours(1));

            var en1 = push.GetAsyncEnumerator();
            var en2 = push.GetAsyncEnumerator();

            var task1 = Task.Run(async() =>
            {
                await en1.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
            });
            var task2 = Task.Run(async() =>
            {
                await en2.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
            });

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Error(new InvalidOperationException());

            await task1;
            await task2;
        }
        public async void Unbounded_Take()
        {
            var push = new ReplayAsyncEnumerable <int>();

            var t1 = push.Take(1).AssertResult(1);

            var t2 = push.Take(2).AssertResult(1, 2);

            await push.Next(1);

            await push.Next(2);

            await t1;

            await t2;
        }
        public async void TimedSized_Bounded_1_Normal()
        {
            var push = new ReplayAsyncEnumerable <int>(1, TimeSpan.FromHours(1));

            await push.Next(1);

            await push.Next(2);

            var t1 = push.AssertResult(2, 3, 4, 5);

            await push.Next(3);

            await push.Next(4);

            await push.Next(5);

            await push.Complete();

            await t1;

            await push.AssertResult(5);
        }
        public async void Sized_Bounded_2_Normal()
        {
            var push = new ReplayAsyncEnumerable <int>(2);

            await push.Next(1);

            await push.Next(2);

            await push.Next(3);

            var t1 = push.AssertResult(2, 3, 4, 5);

            await push.Next(4);

            await push.Next(5);

            await push.Complete();

            await t1;

            await push.AssertResult(4, 5);
        }
Пример #7
0
        public async void Unbounded_No_Consumers_Error()
        {
            var push = new ReplayAsyncEnumerable <int>();

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Error(new InvalidOperationException());

            await push.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);

            await push.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
        }
Пример #8
0
        public async void Unbounded_No_Consumers()
        {
            var push = new ReplayAsyncEnumerable <int>();

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Complete();

            await push.AssertResult(1, 2, 3, 4, 5);

            await push.AssertResult(1, 2, 3, 4, 5);
        }
        public async void TimedSized_No_Consumers_Error()
        {
            var push = new ReplayAsyncEnumerable <int>(10, TimeSpan.FromHours(1));

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Error(new InvalidOperationException());

            await push.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);

            await push.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
        }
        public async void TimedSized_No_Consumers()
        {
            var push = new ReplayAsyncEnumerable <int>(10, TimeSpan.FromHours(1));

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Complete();

            await push.AssertResult(1, 2, 3, 4, 5);

            await push.AssertResult(1, 2, 3, 4, 5);
        }
        public async void Timed_Bounded_1_Normal()
        {
            var timeNow = new [] { 0L };

            var push = new ReplayAsyncEnumerable <int>(10, TimeSpan.FromMilliseconds(100), () => timeNow[0]);

            await push.Next(1);

            timeNow[0] += 100;

            await push.Next(2);

            var t1 = push.AssertResult(2, 3, 4, 5);

            timeNow[0] += 100;

            await push.Next(3);

            timeNow[0] += 100;

            await push.Next(4);

            timeNow[0] += 100;

            await push.Next(5);

            await push.Complete();

            await t1;

            await push.AssertResult(5);

            timeNow[0] += 100;

            await push.AssertResult();
        }
        public async void SizedTimed_Long()
        {
            const long n    = 1_000_000;
            var        push = new ReplayAsyncEnumerable <long>(10, TimeSpan.FromHours(1));
            var        t    = push
                              .Reduce((a, b) => a + b)
                              .AssertResult(n * (n + 1) / 2);

            for (var i = 1; i <= n; i++)
            {
                await push.Next(i);
            }

            await push.Complete();

            await t;
        }
        public async void Unbounded_One_Consumer_Error()
        {
            var push = new ReplayAsyncEnumerable <int>();

            var en1 = push.GetAsyncEnumerator();

            var task1 = Task.Run(async() =>
            {
                await en1.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
            });

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Error(new InvalidOperationException());

            await task1;
        }
        public async void TimedSized_One_Consumer()
        {
            var push = new ReplayAsyncEnumerable <int>(10, TimeSpan.FromHours(1));

            var en1 = push.GetAsyncEnumerator();

            var task1 = Task.Run(async() =>
            {
                await en1.AssertResult(1, 2, 3, 4, 5);
            });

            for (var i = 1; i <= 5; i++)
            {
                await push.Next(i);
            }
            await push.Complete();

            await task1;
        }
        public async void TimedSized_Long_Halfway()
        {
            const long n    = 1_000_000;
            var        push = new ReplayAsyncEnumerable <long>((int)n, TimeSpan.FromHours(1));
            var        t    = default(ValueTask);

            for (var i = 1; i <= n; i++)
            {
                await push.Next(i);

                if (i * 2 == n)
                {
                    t = push
                        .Reduce((a, b) => a + b)
                        .AssertResult(n * (n + 1) / 2);
                }
            }

            await push.Complete();

            await t;
        }