Beispiel #1
0
        public async Task LifeTimeTest(int count)
        {
            int failMod   = 7;
            int cancelMod = 13;

            var clients = Enumerable.Range(0, 35).Select(x => ClientMoq.Get(() => x % failMod == 0 ? "fail" : "good", () =>
            {
                if (x % failMod == 0)
                {
                    throw new SuccessException(x.ToString());
                }
                if (x % cancelMod == 0)
                {
                    throw new TaskCanceledException(x.ToString());
                }
                return(x.ToString());
            }).Object);
            var rollup = new TestRollup(clients);
            var waiter = new TestAwaitable(5000);
            var coord  = new TestedCoordinator(rollup,
                                               onRemove: (x) =>
            {
                if (Interlocked.Increment(ref _lifeTestCounter) == count)
                {
                    waiter.Complete();
                }
            }, msLife: 1);
            var list = await Task.WhenAll(Enumerable.Range(0, count).AsParallel()
                                          .Select((x) => coord.GetToken(new RequestMoq(x.ToString()))).ToList());

            await waiter.Awaiter();

            Assert.IsTrue(_lifeTestCounter == count);
            await Task.CompletedTask;
        }
Beispiel #2
0
        private static async Task SuccessResults(int count, TestAwaitable waiter, TestedCoordinator coord, Func <int, string> requestFunc)
        {
            var list = Task.WhenAll(Enumerable.Range(0, count).AsParallel()
                                    .Select(async(x) => await coord.GetToken(new RequestMoq(requestFunc(x))))
                                    .Select(async(req) =>
            {
                var y = await req;
                var t = coord.ResultAsync(y);
                var r = await t;
                return(new { request = y, response = r });
            }));
            await waiter.Awaiter();

            var result = await list;

            Assert.IsTrue(result.All(x => x?.response != null));
        }
Beispiel #3
0
        public async Task CancelTest(int wait)
        {
            var          waiter              = new TestAwaitable(wait);
            var          clients             = new[] { ClientMoq.Get(() => "", () => "wait", wait) };
            var          rollupSingleWaiting = new TestRollup(clients.Select(x => x.Object));
            var          coord = new TestedCoordinator(rollupSingleWaiting, (x, y, e) => waiter.Fail($"Client Error Sended {x.GetIdentifier()}\n ex: {e}"), (x) => waiter.Complete());
            const string name  = "cancel";
            string       id    = await coord.GetToken(new RequestMoq(name));

            await coord.Cancel(id);

            Models.Response <ResponseMoq> r = new Models.Response <ResponseMoq>();
            var t = coord.Result(id);

            r = await t;
            await waiter.Awaiter();

            Assert.IsTrue(r.GetState() == Models.ResponseState.Deleted);
            await Task.CompletedTask;
        }